()
| 159 | |
| 160 | #[test(tokio::test(flavor = "multi_thread", worker_threads = 2))] |
| 161 | async fn test_three_nodes() -> Result<()> { |
| 162 | let mut test_runner_a = TestRunnerBuilder::new().build().await?; |
| 163 | let mut test_runner_b = TestRunnerBuilder::new().build().await?; |
| 164 | let mut test_runner_c = TestRunnerBuilder::new().build().await?; |
| 165 | |
| 166 | let peer_id_a = test_runner_a.client.local_peer_id().await?; |
| 167 | assert_eq!(test_runner_a.peer_id, peer_id_a); |
| 168 | let peer_id_b = test_runner_b.client.local_peer_id().await?; |
| 169 | assert_eq!(test_runner_b.peer_id, peer_id_b); |
| 170 | let peer_id_c = test_runner_c.client.local_peer_id().await?; |
| 171 | assert_eq!(test_runner_c.peer_id, peer_id_c); |
| 172 | |
| 173 | // connect a to b |
| 174 | test_runner_a |
| 175 | .client |
| 176 | .connect(peer_id_b, vec![test_runner_b.addr.clone()]) |
| 177 | .await?; |
| 178 | |
| 179 | timeout( |
| 180 | Duration::from_millis(500), |
| 181 | wait_bi_connected(&mut test_runner_a, &mut test_runner_b), |
| 182 | ) |
| 183 | .await |
| 184 | .context("waiting for a and b to connect")?; |
| 185 | assert!(is_bi_connected(&test_runner_a, &test_runner_b).await?); |
| 186 | |
| 187 | // connect b to c |
| 188 | test_runner_b |
| 189 | .client |
| 190 | .connect(peer_id_c, vec![test_runner_c.addr.clone()]) |
| 191 | .await?; |
| 192 | |
| 193 | timeout( |
| 194 | Duration::from_millis(500), |
| 195 | wait_bi_connected(&mut test_runner_b, &mut test_runner_c), |
| 196 | ) |
| 197 | .await |
| 198 | .context("waiting for b and c to connect")?; |
| 199 | assert!(is_bi_connected(&test_runner_b, &test_runner_c).await?); |
| 200 | |
| 201 | // We expect that a and c find each other through b and become connected |
| 202 | timeout( |
| 203 | //This one takes longer as we need recon to run and sync peers |
| 204 | Duration::from_millis(3_000), |
| 205 | wait_bi_connected(&mut test_runner_a, &mut test_runner_c), |
| 206 | ) |
| 207 | .await |
| 208 | .context("waiting for a and c to connect")?; |
| 209 | assert!(is_bi_connected(&test_runner_a, &test_runner_c).await?); |
| 210 | |
| 211 | Ok(()) |
| 212 | } |
| 213 | |
| 214 | // Reports if peers are connected to the other peer in both directions |
| 215 | async fn is_bi_connected(a: &TestRunner, b: &TestRunner) -> Result<bool> { |
nothing calls this directly
no test coverage detected