Skip to content

Commit 20ecf34

Browse files
committed
Improve zombinet test
1 parent 3a66f27 commit 20ecf34

1 file changed

Lines changed: 45 additions & 17 deletions

File tree

  • cumulus/zombienet/zombienet-sdk/tests/bootnodes

cumulus/zombienet/zombienet-sdk/tests/bootnodes/mod.rs

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use anyhow::anyhow;
55

6-
use subxt::{OnlineClient, PolkadotConfig};
76
use zombienet_sdk::{NetworkConfig, NetworkConfigBuilder};
87

98
async fn build_network_config() -> Result<NetworkConfig, anyhow::Error> {
@@ -38,8 +37,8 @@ async fn build_network_config() -> Result<NetworkConfig, anyhow::Error> {
3837
"--".into(),
3938
"--no-mdns".into(),
4039
])
41-
.with_collator(|n| n.with_name("collator-0"))
42-
.with_collator(|n| n.with_name("collator-1"))
40+
.with_collator(|n| n.with_name("alpha"))
41+
.with_collator(|n| n.with_name("beta"))
4342
})
4443
.with_global_settings(|global_settings| match std::env::var("ZOMBIENET_SDK_BASE_DIR") {
4544
Ok(val) => global_settings.with_base_dir(val),
@@ -60,26 +59,55 @@ async fn dht_bootnodes_test() -> Result<(), anyhow::Error> {
6059

6160
let config = build_network_config().await?;
6261
let spawn_fn = zombienet_sdk::environment::get_spawn_fn();
63-
let network = spawn_fn(config).await?;
62+
let mut network = spawn_fn(config).await?;
6463

65-
let para_node = network.get_node("collator-0")?;
66-
let para_client: OnlineClient<PolkadotConfig> = para_node.wait_client().await?;
64+
let alpha = network.get_node("alpha")?;
6765

68-
let mut blocks_sub = para_client.blocks().subscribe_all().await?;
66+
// Make sure the collators connect to each other.
67+
alpha
68+
.wait_metric_with_timeout("substrate_sync_peers", |count| count == 1.0, 300u64)
69+
.await?;
6970

70-
// Skip the genesis block.
71-
let genesis_block = blocks_sub.next().await.expect("to receive genesis block")?;
72-
assert_eq!(genesis_block.number(), 0);
71+
// Make sure the DHT bootnode discovery was successful.
72+
alpha
73+
.wait_log_line_count_with_timeout(
74+
".* Parachain bootnode discovery on the relay chain DHT succeeded",
75+
false,
76+
1,
77+
30u64,
78+
)
79+
.await?;
7380

74-
// Producing the first block is a good indicator the colators have connected to each other.
75-
let first_block = blocks_sub.next().await.expect("to receive first block")?;
76-
assert_eq!(first_block.number(), 1);
81+
log::info!(
82+
"First two collators successfully connected via DHT bootnodes. \
83+
Waiting 150 secs for two sessions to pass."
84+
);
85+
86+
// Wait for two sessions (2 min + 30 sec extra) and spawn a new collator to check the bootnode
87+
// is also advertised with the new epoch key (republishing works).
88+
tokio::time::sleep(std::time::Duration::from_secs(150)).await;
89+
90+
log::info!("Spawning a third collator.");
91+
network.add_collator("gamma", Default::default(), 1000).await?;
92+
93+
let gamma = network.get_node("gamma")?;
94+
95+
// Make sure the new collator has connected to the existing collators.
96+
gamma
97+
.wait_metric_with_timeout("substrate_sync_peers", |count| count == 2.0, 300u64)
98+
.await?;
7799

78-
// Make sure we are connected to another collator. This can be not the case if the collator
79-
// produced a block locally without actually talking to another collator.
80-
assert!(para_node.assert("substrate_sync_peers", 1).await?);
100+
// Make sure the DHT bootnode discovery was successful.
101+
gamma
102+
.wait_log_line_count_with_timeout(
103+
".* Parachain bootnode discovery on the relay chain DHT succeeded",
104+
false,
105+
1,
106+
30u64,
107+
)
108+
.await?;
81109

82-
log::info!("Test finished successfully");
110+
log::info!("Test finished successfully.");
83111

84112
Ok(())
85113
}

0 commit comments

Comments
 (0)