Skip to content

Commit efd9ba2

Browse files
committed
test(p2p): run scenarios in sequence
... when running with `cargo test ...`
1 parent 860886b commit efd9ba2

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

node/testing/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
mod exit_with_error;
2+
3+
use std::sync::Arc;
4+
25
pub use exit_with_error::exit_with_error;
36

47
pub mod cluster;
@@ -13,6 +16,7 @@ pub mod ocaml;
1316

1417
mod server;
1518
pub use server::server;
19+
use tokio::sync::{Mutex, MutexGuard};
1620

1721
pub fn setup() -> tokio::runtime::Runtime {
1822
// openmina_node_native::tracing::initialize(openmina_node_native::tracing::Level::DEBUG);
@@ -41,3 +45,22 @@ pub fn setup_without_rt() {
4145
};
4246
*INIT;
4347
}
48+
49+
lazy_static::lazy_static! {
50+
static ref GATE: Arc<Mutex<()>> = Arc::new(Mutex::new(()));
51+
}
52+
53+
pub struct TestGate(MutexGuard<'static, ()>);
54+
55+
impl TestGate {
56+
async fn there_can_be_only_one() -> Self {
57+
Self(GATE.lock().await)
58+
}
59+
pub fn release(self) {
60+
61+
}
62+
}
63+
64+
pub async fn wait_for_other_tests() -> TestGate {
65+
TestGate::there_can_be_only_one().await
66+
}

node/testing/tests/common.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ macro_rules! scenario_test {
1616
use openmina_node_testing::{
1717
cluster::{Cluster, ClusterConfig},
1818
scenarios::ClusterRunner,
19+
setup_without_rt, wait_for_other_tests,
1920
};
2021
use std::io::Write;
2122

23+
setup_without_rt();
24+
let w = wait_for_other_tests().await;
25+
2226
if let Some(summary) = std::env::var_os("GITHUB_STEP_SUMMARY") {
2327
let _ = std::fs::File::options()
2428
.append(true)
@@ -40,9 +44,9 @@ macro_rules! scenario_test {
4044
if let Some((file, line)) = panic_info.location().map(|l| (l.file(), l.line()))
4145
{
4246
if let Some(message) = panic_info.payload().downcast_ref::<&str>() {
43-
eprintln!("\n::error file={file},line={line}::{message}");
47+
println!("\n::error file={file},line={line}::{message}");
4448
} else {
45-
eprintln!("\n::error file={file},line={line}::panic without a message");
49+
println!("\n::error file={file},line={line}::panic without a message");
4650
}
4751
}
4852
prev_panic_hook(panic_info);
@@ -61,6 +65,7 @@ macro_rules! scenario_test {
6165
.open(&summary)
6266
.and_then(|mut f| writeln!(f, "**PASSED** :white_check_mark:"));
6367
}
68+
w.release();
6469
}
6570
};
6671
}

0 commit comments

Comments
 (0)