Skip to content

Commit 250bebd

Browse files
committed
wip
1 parent bd23071 commit 250bebd

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

crates/utils/src/bin/generate_migration_db.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/// Binary to generate pre-migrated database snapshots for testing.
22
///
33
/// These snapshots are loaded by `TestNode::new_with_spawn_and_move_db()` and
4-
/// `TestNode::new_with_simple_db()` to avoid the slow migration process (git clone + scarb build +
5-
/// sozo migrate) in each test run.
4+
/// `TestNode::new_with_simple_db()` to avoid the slow migration process (git clone + scarb
5+
/// build + sozo migrate) in each test run.
66
///
77
/// Usage:
8-
/// cargo run --bin generate_migration_db --features node -- --example spawn-and-move --output tests/fixtures/db/spawn_and_move.tar.gz
9-
/// cargo run --bin generate_migration_db --features node -- --example simple --output tests/fixtures/db/simple.tar.gz
8+
/// cargo run --bin generate_migration_db --features node -- --example spawn-and-move
9+
/// --output tests/fixtures/db/spawn_and_move.tar.gz cargo run --bin generate_migration_db
10+
/// --features node -- --example simple --output tests/fixtures/db/simple.tar.gz
1011
use std::path::{Path, PathBuf};
1112
use std::process::Command;
1213

crates/utils/src/node.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ where
5252
<P as ProviderFactory>::ProviderMut: ProviderRW,
5353
{
5454
node: LaunchedNode<P>,
55+
/// Temp directory holding a copied database snapshot. Cleaned up on drop.
56+
_db_temp_dir: Option<tempfile::TempDir>,
5557
}
5658

5759
impl TestNode {
@@ -72,6 +74,7 @@ impl TestNode {
7274
.launch()
7375
.await
7476
.expect("failed to launch node"),
77+
_db_temp_dir: None,
7578
}
7679
}
7780

@@ -88,10 +91,7 @@ impl TestNode {
8891
/// Copies the database to a temp directory so each test gets its own mutable copy.
8992
/// The database is opened with [`SyncMode::UtterlyNoSync`] for test performance.
9093
pub async fn new_from_db_with_config(db_path: &Path, config: Config) -> Self {
91-
let temp_dir = tempfile::Builder::new()
92-
.disable_cleanup(true)
93-
.tempdir()
94-
.expect("failed to create temp dir");
94+
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");
9595

9696
copy_db_dir(db_path, temp_dir.path()).expect("failed to copy database");
9797

@@ -104,6 +104,7 @@ impl TestNode {
104104
.launch()
105105
.await
106106
.expect("failed to launch node"),
107+
_db_temp_dir: Some(temp_dir),
107108
}
108109
}
109110

@@ -131,6 +132,7 @@ impl ForkTestNode {
131132
.launch()
132133
.await
133134
.expect("failed to launch node"),
135+
_db_temp_dir: None,
134136
}
135137
}
136138
}

tests/fixtures/db/simple.tar.gz

1.48 MB
Binary file not shown.
2.72 MB
Binary file not shown.

0 commit comments

Comments
 (0)