Skip to content

Commit a3105fd

Browse files
committed
feat(testing): specify default cluster config in an individual scenario
1 parent d038a34 commit a3105fd

File tree

5 files changed

+43
-23
lines changed

5 files changed

+43
-23
lines changed

node/testing/src/cluster/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl ClusterConfig {
3939
})
4040
}
4141

42-
pub fn use_debugger(mut self) -> Self {
42+
pub fn use_debugger(&mut self) -> &mut Self {
4343
self.use_debugger = true;
4444
self
4545
}
@@ -48,7 +48,7 @@ impl ClusterConfig {
4848
self.use_debugger
4949
}
5050

51-
pub fn set_replay(mut self) -> Self {
51+
pub fn set_replay(&mut self) -> &mut Self {
5252
self.is_replay = true;
5353
self
5454
}
@@ -62,7 +62,7 @@ impl ClusterConfig {
6262
(range.0)..=(range.1)
6363
}
6464

65-
pub fn set_all_rust_to_rust_use_webrtc(mut self) -> Self {
65+
pub fn set_all_rust_to_rust_use_webrtc(&mut self) -> &mut Self {
6666
assert!(cfg!(feature = "p2p-webrtc"));
6767
self.all_rust_to_rust_use_webrtc = true;
6868
self
@@ -76,7 +76,7 @@ impl ClusterConfig {
7676
self.proof_kind
7777
}
7878

79-
pub fn set_ocaml_node_executable(mut self, executable: OcamlNodeExecutable) -> Self {
79+
pub fn set_ocaml_node_executable(&mut self, executable: OcamlNodeExecutable) -> &mut Self {
8080
self.ocaml_node_executable = Some(executable);
8181
self
8282
}

node/testing/src/main.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,32 +72,27 @@ impl Command {
7272
Self::ScenariosGenerate(cmd) => {
7373
#[cfg(feature = "scenario-generators")]
7474
{
75-
let config = ClusterConfig::new(None).map_err(|err| {
76-
anyhow::anyhow!("failed to create cluster configuration: {err}")
77-
})?;
78-
let config = if cmd.use_debugger {
79-
config.use_debugger()
80-
} else {
81-
config
75+
let run_scenario = |scenario: Scenarios| -> Result<_, anyhow::Error> {
76+
let mut config = scenario.default_cluster_config()?;
77+
if cmd.use_debugger {
78+
config.use_debugger();
79+
}
80+
Ok(scenario.run_only_from_scratch(config))
8281
};
83-
8482
let fut = async move {
8583
if let Some(name) = cmd.name {
8684
if let Some(scenario) = Scenarios::find_by_name(&name) {
87-
scenario.run_only_from_scratch(config).await;
88-
// scenario.run_and_save_from_scratch(config).await;
85+
run_scenario(scenario)?.await;
8986
} else {
9087
anyhow::bail!("no such scenario: \"{name}\"");
9188
}
9289
} else {
9390
for scenario in Scenarios::iter() {
94-
scenario.run_only_from_scratch(config.clone()).await;
95-
// scenario.run_and_save_from_scratch(config.clone()).await;
91+
run_scenario(scenario)?.await;
9692
}
9793
}
9894
Ok(())
9995
};
100-
10196
rt.block_on(async {
10297
tokio::select! {
10398
res = fut => res,
@@ -113,10 +108,10 @@ impl Command {
113108
.into())
114109
}
115110
Self::ScenariosRun(cmd) => {
116-
let config = ClusterConfig::new(None).map_err(|err| {
111+
let mut config = ClusterConfig::new(None).map_err(|err| {
117112
anyhow::anyhow!("failed to create cluster configuration: {err}")
118113
})?;
119-
let config = config.set_replay();
114+
config.set_replay();
120115

121116
let id = cmd.name.parse()?;
122117
let fut = async move {

node/testing/src/scenarios/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::scenario::{Scenario, ScenarioId, ScenarioStep};
2929

3030
use self::multi_node::basic_connectivity_initial_joining::MultiNodeBasicConnectivityInitialJoining;
3131
use self::multi_node::basic_connectivity_peer_discovery::MultiNodeBasicConnectivityPeerDiscovery;
32+
use self::multi_node::connection_discovery::RustNodeAsSeed as P2pConnectionDiscoveryRustNodeAsSeed;
3233
use self::multi_node::pubsub_advanced::MultiNodePubsubPropagateBlock;
3334
use self::multi_node::sync_4_block_producers::MultiNodeSync4BlockProducers;
3435
use self::multi_node::vrf_correct_ledgers::MultiNodeVrfGetCorrectLedgers;
@@ -68,6 +69,7 @@ pub enum Scenarios {
6869
SimulationSmallForeverRealTime(SimulationSmallForeverRealTime),
6970
P2pReceiveBlock(P2pReceiveBlock),
7071
P2pSignaling(P2pSignaling),
72+
P2pConnectionDiscoveryRustNodeAsSeed(P2pConnectionDiscoveryRustNodeAsSeed),
7173
MultiNodePubsubPropagateBlock(MultiNodePubsubPropagateBlock),
7274
RecordReplayBootstrap(RecordReplayBootstrap),
7375
RecordReplayBlockProduction(RecordReplayBlockProduction),
@@ -152,12 +154,25 @@ impl Scenarios {
152154
Self::SimulationSmallForeverRealTime(_) => SimulationSmallForeverRealTime::DOCS,
153155
Self::P2pReceiveBlock(_) => P2pReceiveBlock::DOCS,
154156
Self::P2pSignaling(_) => P2pSignaling::DOCS,
157+
Self::P2pConnectionDiscoveryRustNodeAsSeed(_) => {
158+
P2pConnectionDiscoveryRustNodeAsSeed::DOCS
159+
}
155160
Self::MultiNodePubsubPropagateBlock(_) => MultiNodePubsubPropagateBlock::DOCS,
156161
Self::RecordReplayBootstrap(_) => RecordReplayBootstrap::DOCS,
157162
Self::RecordReplayBlockProduction(_) => RecordReplayBlockProduction::DOCS,
158163
}
159164
}
160165

166+
pub fn default_cluster_config(self) -> Result<ClusterConfig, anyhow::Error> {
167+
let config = ClusterConfig::new(None)
168+
.map_err(|err| anyhow::anyhow!("failed to create cluster configuration: {err}"))?;
169+
170+
match self {
171+
Self::P2pSignaling(v) => v.default_cluster_config(config),
172+
_ => Ok(config),
173+
}
174+
}
175+
161176
pub fn blank_scenario(self) -> Scenario {
162177
let mut scenario = Scenario::new(self.id(), self.parent_id());
163178
scenario.set_description(self.description().to_owned());
@@ -189,6 +204,7 @@ impl Scenarios {
189204
Self::SimulationSmallForeverRealTime(v) => v.run(runner).await,
190205
Self::P2pReceiveBlock(v) => v.run(runner).await,
191206
Self::P2pSignaling(v) => v.run(runner).await,
207+
Self::P2pConnectionDiscoveryRustNodeAsSeed(v) => v.run(runner).await,
192208
Self::MultiNodePubsubPropagateBlock(v) => v.run(runner).await,
193209
Self::RecordReplayBootstrap(v) => v.run(runner).await,
194210
Self::RecordReplayBlockProduction(v) => v.run(runner).await,

node/testing/src/scenarios/p2p/signaling.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use node::{
66
};
77

88
use crate::{
9+
cluster::ClusterConfig,
910
node::RustNodeTestingConfig,
1011
scenarios::{ClusterRunner, DynEffectsData, RunCfg},
1112
};
@@ -16,6 +17,14 @@ use crate::{
1617
pub struct P2pSignaling;
1718

1819
impl P2pSignaling {
20+
pub fn default_cluster_config(
21+
self,
22+
mut config: ClusterConfig,
23+
) -> Result<ClusterConfig, anyhow::Error> {
24+
config.set_all_rust_to_rust_use_webrtc();
25+
Ok(config)
26+
}
27+
1928
pub async fn run(self, mut runner: ClusterRunner<'_>) {
2029
const NODES_N: usize = 4;
2130

node/testing/tests/common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ macro_rules! scenario_test {
1818
$(#[$meta])?
1919
async fn $name() {
2020
use openmina_node_testing::{
21-
cluster::{Cluster, ClusterConfig},
22-
scenarios::ClusterRunner,
21+
cluster::Cluster,
22+
scenarios::{ClusterRunner, Scenarios},
2323
setup_without_rt, wait_for_other_tests,
2424
};
2525
use std::io::Write;
@@ -57,16 +57,16 @@ macro_rules! scenario_test {
5757
}));
5858
}
5959

60+
let scenario = $scenario_instance;
6061
#[allow(unused_mut)]
61-
let mut config = ClusterConfig::new(None).unwrap();
62+
let mut config = Scenarios::from(scenario).default_cluster_config().unwrap();
6263
#[cfg(feature = "p2p-webrtc")]
6364
if $can_test_webrtc {
6465
eprintln!("All rust to rust connections will be over webrtc transport");
6566
config = config.set_all_rust_to_rust_use_webrtc();
6667
}
6768
let mut cluster = Cluster::new(config);
6869
let runner = ClusterRunner::new(&mut cluster, |_| {});
69-
let scenario = $scenario_instance;
7070
scenario.run(runner).await;
7171

7272
if let Some(summary) = std::env::var_os("GITHUB_STEP_SUMMARY") {

0 commit comments

Comments
 (0)