Skip to content

Commit 45fba39

Browse files
committed
feat(testing): specify default cluster config in an individual scenario
1 parent e179d99 commit 45fba39

File tree

5 files changed

+123
-24
lines changed

5 files changed

+123
-24
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: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub mod p2p;
1818

1919
mod driver;
2020
pub use driver::*;
21-
use p2p::signaling::P2pSignaling;
2221

2322
pub use crate::cluster::runner::*;
2423

@@ -29,13 +28,31 @@ use crate::scenario::{Scenario, ScenarioId, ScenarioStep};
2928

3029
use self::multi_node::basic_connectivity_initial_joining::MultiNodeBasicConnectivityInitialJoining;
3130
use self::multi_node::basic_connectivity_peer_discovery::MultiNodeBasicConnectivityPeerDiscovery;
31+
use self::multi_node::connection_discovery::RustNodeAsSeed as P2pConnectionDiscoveryRustNodeAsSeed;
32+
use self::multi_node::connection_discovery::{
33+
OCamlToRust, OCamlToRustViaSeed, RustToOCaml, RustToOCamlViaSeed,
34+
};
3235
use self::multi_node::pubsub_advanced::MultiNodePubsubPropagateBlock;
3336
use self::multi_node::sync_4_block_producers::MultiNodeSync4BlockProducers;
3437
use self::multi_node::vrf_correct_ledgers::MultiNodeVrfGetCorrectLedgers;
3538
use self::multi_node::vrf_correct_slots::MultiNodeVrfGetCorrectSlots;
3639
use self::multi_node::vrf_epoch_bounds_correct_ledgers::MultiNodeVrfEpochBoundsCorrectLedger;
3740
use self::multi_node::vrf_epoch_bounds_evaluation::MultiNodeVrfEpochBoundsEvaluation;
41+
use self::p2p::basic_connection_handling::{
42+
AllNodesConnectionsAreSymmetric, MaxNumberOfPeersIncoming, MaxNumberOfPeersIs1,
43+
SeedConnectionsAreSymmetric, SimultaneousConnections,
44+
};
45+
use self::p2p::basic_incoming_connections::{
46+
AcceptIncomingConnection, AcceptMultipleIncomingConnections,
47+
};
48+
use self::p2p::basic_outgoing_connections::{
49+
ConnectToInitialPeers, ConnectToInitialPeersBecomeReady, ConnectToUnavailableInitialPeers,
50+
DontConnectToInitialPeerWithSameId, DontConnectToNodeWithSameId, DontConnectToSelfInitialPeer,
51+
MakeMultipleOutgoingConnections, MakeOutgoingConnection,
52+
};
53+
use self::p2p::kademlia::KademliaBootstrap;
3854
use self::p2p::pubsub::P2pReceiveBlock;
55+
use self::p2p::signaling::P2pSignaling;
3956
use self::record_replay::block_production::RecordReplayBlockProduction;
4057
use self::record_replay::bootstrap::RecordReplayBootstrap;
4158
use self::simulation::small::SimulationSmall;
@@ -68,9 +85,31 @@ pub enum Scenarios {
6885
SimulationSmallForeverRealTime(SimulationSmallForeverRealTime),
6986
P2pReceiveBlock(P2pReceiveBlock),
7087
P2pSignaling(P2pSignaling),
88+
P2pConnectionDiscoveryRustNodeAsSeed(P2pConnectionDiscoveryRustNodeAsSeed),
7189
MultiNodePubsubPropagateBlock(MultiNodePubsubPropagateBlock),
7290
RecordReplayBootstrap(RecordReplayBootstrap),
7391
RecordReplayBlockProduction(RecordReplayBlockProduction),
92+
93+
RustToOCaml(RustToOCaml),
94+
OCamlToRust(OCamlToRust),
95+
OCamlToRustViaSeed(OCamlToRustViaSeed),
96+
RustToOCamlViaSeed(RustToOCamlViaSeed),
97+
KademliaBootstrap(KademliaBootstrap),
98+
AcceptIncomingConnection(AcceptIncomingConnection),
99+
MakeOutgoingConnection(MakeOutgoingConnection),
100+
AcceptMultipleIncomingConnections(AcceptMultipleIncomingConnections),
101+
MakeMultipleOutgoingConnections(MakeMultipleOutgoingConnections),
102+
DontConnectToNodeWithSameId(DontConnectToNodeWithSameId),
103+
DontConnectToInitialPeerWithSameId(DontConnectToInitialPeerWithSameId),
104+
DontConnectToSelfInitialPeer(DontConnectToSelfInitialPeer),
105+
SimultaneousConnections(SimultaneousConnections),
106+
ConnectToInitialPeers(ConnectToInitialPeers),
107+
ConnectToUnavailableInitialPeers(ConnectToUnavailableInitialPeers),
108+
AllNodesConnectionsAreSymmetric(AllNodesConnectionsAreSymmetric),
109+
ConnectToInitialPeersBecomeReady(ConnectToInitialPeersBecomeReady),
110+
SeedConnectionsAreSymmetric(SeedConnectionsAreSymmetric),
111+
MaxNumberOfPeersIncoming(MaxNumberOfPeersIncoming),
112+
MaxNumberOfPeersIs1(MaxNumberOfPeersIs1),
74113
}
75114

76115
impl Scenarios {
@@ -152,9 +191,43 @@ impl Scenarios {
152191
Self::SimulationSmallForeverRealTime(_) => SimulationSmallForeverRealTime::DOCS,
153192
Self::P2pReceiveBlock(_) => P2pReceiveBlock::DOCS,
154193
Self::P2pSignaling(_) => P2pSignaling::DOCS,
194+
Self::P2pConnectionDiscoveryRustNodeAsSeed(_) => {
195+
P2pConnectionDiscoveryRustNodeAsSeed::DOCS
196+
}
155197
Self::MultiNodePubsubPropagateBlock(_) => MultiNodePubsubPropagateBlock::DOCS,
156198
Self::RecordReplayBootstrap(_) => RecordReplayBootstrap::DOCS,
157199
Self::RecordReplayBlockProduction(_) => RecordReplayBlockProduction::DOCS,
200+
201+
Self::RustToOCaml(_) => RustToOCaml::DOCS,
202+
Self::OCamlToRust(_) => OCamlToRust::DOCS,
203+
Self::OCamlToRustViaSeed(_) => OCamlToRustViaSeed::DOCS,
204+
Self::RustToOCamlViaSeed(_) => RustToOCamlViaSeed::DOCS,
205+
Self::KademliaBootstrap(_) => KademliaBootstrap::DOCS,
206+
Self::AcceptIncomingConnection(_) => AcceptIncomingConnection::DOCS,
207+
Self::MakeOutgoingConnection(_) => MakeOutgoingConnection::DOCS,
208+
Self::AcceptMultipleIncomingConnections(_) => AcceptMultipleIncomingConnections::DOCS,
209+
Self::MakeMultipleOutgoingConnections(_) => MakeMultipleOutgoingConnections::DOCS,
210+
Self::DontConnectToNodeWithSameId(_) => DontConnectToNodeWithSameId::DOCS,
211+
Self::DontConnectToInitialPeerWithSameId(_) => DontConnectToInitialPeerWithSameId::DOCS,
212+
Self::DontConnectToSelfInitialPeer(_) => DontConnectToSelfInitialPeer::DOCS,
213+
Self::SimultaneousConnections(_) => SimultaneousConnections::DOCS,
214+
Self::ConnectToInitialPeers(_) => ConnectToInitialPeers::DOCS,
215+
Self::ConnectToUnavailableInitialPeers(_) => ConnectToUnavailableInitialPeers::DOCS,
216+
Self::AllNodesConnectionsAreSymmetric(_) => AllNodesConnectionsAreSymmetric::DOCS,
217+
Self::ConnectToInitialPeersBecomeReady(_) => ConnectToInitialPeersBecomeReady::DOCS,
218+
Self::SeedConnectionsAreSymmetric(_) => SeedConnectionsAreSymmetric::DOCS,
219+
Self::MaxNumberOfPeersIncoming(_) => MaxNumberOfPeersIncoming::DOCS,
220+
Self::MaxNumberOfPeersIs1(_) => MaxNumberOfPeersIs1::DOCS,
221+
}
222+
}
223+
224+
pub fn default_cluster_config(self) -> Result<ClusterConfig, anyhow::Error> {
225+
let config = ClusterConfig::new(None)
226+
.map_err(|err| anyhow::anyhow!("failed to create cluster configuration: {err}"))?;
227+
228+
match self {
229+
Self::P2pSignaling(v) => v.default_cluster_config(config),
230+
_ => Ok(config),
158231
}
159232
}
160233

@@ -189,9 +262,31 @@ impl Scenarios {
189262
Self::SimulationSmallForeverRealTime(v) => v.run(runner).await,
190263
Self::P2pReceiveBlock(v) => v.run(runner).await,
191264
Self::P2pSignaling(v) => v.run(runner).await,
265+
Self::P2pConnectionDiscoveryRustNodeAsSeed(v) => v.run(runner).await,
192266
Self::MultiNodePubsubPropagateBlock(v) => v.run(runner).await,
193267
Self::RecordReplayBootstrap(v) => v.run(runner).await,
194268
Self::RecordReplayBlockProduction(v) => v.run(runner).await,
269+
270+
Self::RustToOCaml(v) => v.run(runner).await,
271+
Self::OCamlToRust(v) => v.run(runner).await,
272+
Self::OCamlToRustViaSeed(v) => v.run(runner).await,
273+
Self::RustToOCamlViaSeed(v) => v.run(runner).await,
274+
Self::KademliaBootstrap(v) => v.run(runner).await,
275+
Self::AcceptIncomingConnection(v) => v.run(runner).await,
276+
Self::MakeOutgoingConnection(v) => v.run(runner).await,
277+
Self::AcceptMultipleIncomingConnections(v) => v.run(runner).await,
278+
Self::MakeMultipleOutgoingConnections(v) => v.run(runner).await,
279+
Self::DontConnectToNodeWithSameId(v) => v.run(runner).await,
280+
Self::DontConnectToInitialPeerWithSameId(v) => v.run(runner).await,
281+
Self::DontConnectToSelfInitialPeer(v) => v.run(runner).await,
282+
Self::SimultaneousConnections(v) => v.run(runner).await,
283+
Self::ConnectToInitialPeers(v) => v.run(runner).await,
284+
Self::ConnectToUnavailableInitialPeers(v) => v.run(runner).await,
285+
Self::AllNodesConnectionsAreSymmetric(v) => v.run(runner).await,
286+
Self::ConnectToInitialPeersBecomeReady(v) => v.run(runner).await,
287+
Self::SeedConnectionsAreSymmetric(v) => v.run(runner).await,
288+
Self::MaxNumberOfPeersIncoming(v) => v.run(runner).await,
289+
Self::MaxNumberOfPeersIs1(v) => v.run(runner).await,
195290
}
196291
}
197292

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)