|
1 | 1 | #[cfg(test)]
|
2 | 2 | pub mod test {
|
3 | 3 |
|
| 4 | + use anyhow::Context; |
4 | 5 | use mtma_migrator_test_accounts_equal_criterion::AccountsEqual;
|
5 | 6 | use mtma_migrator_test_types::check::checked_migration;
|
6 | 7 | use mtma_migrator_types::migrator::{movement_migrator::Overlays, MovementMigrator};
|
7 | 8 | use mtma_node_null_core::config::Config as MtmaNullConfig;
|
8 | 9 | use mtma_node_test_types::prelude::Prelude;
|
| 10 | + use tracing::info; |
9 | 11 |
|
10 |
| - #[tokio::test] |
| 12 | + #[tokio::test(flavor = "multi_thread")] |
11 | 13 | #[tracing_test::traced_test]
|
12 | 14 | async fn test_accounts_equal() -> Result<(), anyhow::Error> {
|
13 |
| - // Form the migrator. |
14 |
| - let mut movement_migrator = MovementMigrator::try_debug_home()?; |
15 |
| - movement_migrator.set_overlays(Overlays::default()); |
16 |
| - |
17 |
| - // Start the migrator so that it's running in the background. |
18 |
| - // In the future, some migrators may be for already running nodes. |
19 |
| - let movement_migrator_for_task = movement_migrator.clone(); |
20 |
| - let movement_migrator_task = kestrel::task(async move { |
21 |
| - movement_migrator_for_task.run().await?; |
22 |
| - Ok::<_, anyhow::Error>(()) |
23 |
| - }); |
24 |
| - |
25 |
| - tokio::time::sleep(tokio::time::Duration::from_secs(30)).await; |
26 |
| - |
27 |
| - kestrel::end!(movement_migrator_task)?; |
28 |
| - |
29 |
| - // Form the prelude. |
30 |
| - // todo: this needs to be updated to use the prelude generator |
31 |
| - let prelude = Prelude::new_empty(); |
32 |
| - |
33 |
| - // Form the migration. |
34 |
| - let migration_config = MtmaNullConfig::default(); |
35 |
| - let migration = migration_config.build()?; |
36 |
| - |
37 |
| - // Run the checked migration. |
38 |
| - let accounts_equal = AccountsEqual::new(); |
39 |
| - checked_migration(&mut movement_migrator, &prelude, &migration, vec![accounts_equal]) |
40 |
| - .await?; |
| 15 | + // use a scope to ensure everything is dropped |
| 16 | + { |
| 17 | + // Form the migrator. |
| 18 | + let mut movement_migrator = MovementMigrator::try_temp()?; |
| 19 | + movement_migrator.set_overlays(Overlays::default()); |
| 20 | + |
| 21 | + // Start the migrator so that it's running in the background. |
| 22 | + // In the future, some migrators may be for already running nodes. |
| 23 | + let movement_migrator_for_task = movement_migrator.clone(); |
| 24 | + let movement_migrator_task = kestrel::task(async move { |
| 25 | + movement_migrator_for_task.run().await?; |
| 26 | + Ok::<_, anyhow::Error>(()) |
| 27 | + }); |
| 28 | + |
| 29 | + // wait for the rest client to be ready |
| 30 | + // once we have this, there should also be a config, so we can then kill off the migrator and proceed |
| 31 | + movement_migrator |
| 32 | + .wait_for_rest_client_ready(tokio::time::Duration::from_secs(600)) // we wait for up to ten minutes because the nix flake in .vendors/movementcan be a bit slow the first time |
| 33 | + .await |
| 34 | + .context( |
| 35 | + "failed to wait for movement migrator rest client while running accounts equal manual prelude", |
| 36 | + )?; |
| 37 | + |
| 38 | + kestrel::end!(movement_migrator_task)?; |
| 39 | + |
| 40 | + // Form the prelude. |
| 41 | + // todo: this needs to be updated to use the prelude generator |
| 42 | + let prelude = Prelude::new_empty(); |
| 43 | + |
| 44 | + // Form the migration. |
| 45 | + let migration_config = MtmaNullConfig::default(); |
| 46 | + let migration = migration_config.build()?; |
| 47 | + |
| 48 | + // Run the checked migration. |
| 49 | + let accounts_equal = AccountsEqual::new(); |
| 50 | + info!("Running migration"); |
| 51 | + match checked_migration( |
| 52 | + &mut movement_migrator, |
| 53 | + &prelude, |
| 54 | + &migration, |
| 55 | + vec![accounts_equal], |
| 56 | + ) |
| 57 | + .await |
| 58 | + { |
| 59 | + Ok(()) => {} |
| 60 | + Err(e) => { |
| 61 | + info!("Migration failed: {:?}", e); |
| 62 | + return Err(anyhow::anyhow!("Migration failed: {:?}", e)); |
| 63 | + } |
| 64 | + } |
| 65 | + info!("Migration succeeded"); |
| 66 | + } |
| 67 | + |
| 68 | + // exit the test is fine when you only have one test per crate because when cargo test is run across a workspace, it actually multi-processes the tests by crate |
| 69 | + std::process::exit(0); |
41 | 70 |
|
42 | 71 | Ok(())
|
43 | 72 | }
|
|
0 commit comments