Skip to content

Commit 9b01751

Browse files
tests: improve patchbay test setup (#4078)
## Description * ignore tests currently known as being flaky * no longer retry failed tests. the reruns would write into the same testdir, making debugging the failures very hard especially if the retry succeeded * improve logging in case of failures --------- Co-authored-by: Friedel Ziegelmayer <me@dignifiedquire.com>
1 parent 8bf7002 commit 9b01751

3 files changed

Lines changed: 59 additions & 20 deletions

File tree

.config/nextest.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ slow-timeout = { period = "10s", terminate-after = 3 }
2020

2121
[profile.patchbay]
2222
fail-fast = false
23-
retries = 1
2423
test-threads = 4
2524
default-filter = 'binary(patchbay)'
2625
slow-timeout = { period = "30s", terminate-after = 4 }

iroh/tests/patchbay.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ async fn holepunch_simple() -> Result {
7474
.client(client, async move |_dev, _ep, conn| {
7575
let mut paths = conn.paths();
7676
assert!(paths.selected().is_relay(), "connection started relayed");
77-
paths.wait_ip(timeout).await?;
77+
paths
78+
.wait_ip(timeout)
79+
.await
80+
.context("holepunch to direct")?;
7881
info!("connection became direct");
7982
Ok(())
8083
})
@@ -133,7 +136,10 @@ async fn switch_uplink_v4() -> Result {
133136
assert!(paths.selected().is_relay(), "connection started relayed");
134137

135138
// Wait for conn to become direct.
136-
paths.wait_ip(timeout).await.context("become direct")?;
139+
paths
140+
.wait_ip(timeout)
141+
.await
142+
.context("holepunch to direct")?;
137143

138144
// Wait a little more and then switch wifis.
139145
tokio::time::sleep(Duration::from_secs(1)).await;
@@ -225,17 +231,24 @@ async fn switch_uplink_v6() -> Result {
225231
assert!(paths.selected().is_relay(), "connection started relayed");
226232

227233
// Wait for conn to become direct.
228-
paths.wait_ip(timeout).await.context("become direct")?;
234+
paths
235+
.wait_ip(timeout)
236+
.await
237+
.context("holepunch to direct")?;
229238

230-
ping_open(&conn, timeout).await.context("ping_open 1")?;
239+
ping_open(&conn, timeout)
240+
.await
241+
.context("ping before switch")?;
231242

232-
info!("switch IP uplink");
243+
info!("switch IP uplink to v6");
233244
dev.replug_iface("eth0", mobile.id()).await?;
234245

235246
// We don't assert any path changes here, because the remote stays identical,
236247
// and PathInfo does not contain info on local addrs. Instead, the remote
237248
// only accepts our ping after the path changed.
238-
ping_open(&conn, timeout).await.context("ping_open 2")?;
249+
ping_open(&conn, timeout)
250+
.await
251+
.context("ping after v6 switch")?;
239252
Ok(())
240253
})
241254
.run()
@@ -253,6 +266,7 @@ async fn switch_uplink_v6() -> Result {
253266
/// faster LAN address. A ping verifies the new path works.
254267
#[tokio::test]
255268
#[traced_test]
269+
#[ignore = "sometimes is flaky (does not become direct after the link_up)"]
256270
async fn change_ifaces() -> Result {
257271
let (lab, relay_map, _relay_guard, guard) = lab_with_relay(testdir!()).await?;
258272
let nat1 = lab.add_router("nat1").nat(Nat::Home).build().await?;
@@ -275,7 +289,7 @@ async fn change_ifaces() -> Result {
275289
.await?;
276290
client.link_down("eth1").await?;
277291

278-
let timeout = Duration::from_secs(10);
292+
let timeout = Duration::from_secs(15);
279293
Pair::new(relay_map)
280294
.server(server, async move |_dev, _ep, conn| {
281295
ping_accept(&conn, timeout).await.context("ping_accept")?;
@@ -478,14 +492,19 @@ async fn run_degrade_level(impaired_side: Side, level: usize) -> Result<TestGuar
478492
timeout * 2,
479493
Pair::new(relay_map)
480494
.server(server, async move |_dev, _ep, conn| {
481-
ping_accept(&conn, timeout).await?;
495+
ping_accept(&conn, timeout).await.context("ping_accept")?;
482496
conn.closed().await;
483497
Ok(())
484498
})
485499
.client(client, async move |_dev, _ep, conn| {
486500
let mut paths = conn.paths();
487-
paths.wait_ip(timeout).await?;
488-
ping_open(&conn, timeout).await?;
501+
paths
502+
.wait_ip(timeout)
503+
.await
504+
.context("holepunch to direct")?;
505+
info!("direct path established, sending ping");
506+
ping_open(&conn, timeout).await.context("ping_open")?;
507+
info!("ping complete");
489508
Ok(())
490509
})
491510
.run(),
@@ -545,6 +564,7 @@ async fn degrade_server_2_bad() -> Result {
545564

546565
#[tokio::test]
547566
#[traced_test]
567+
#[ignore = "not yet passing reliably"]
548568
async fn degrade_server_3_terrible() -> Result {
549569
run_degrade_level(Side::Server, 3).await?.ok();
550570
Ok(())
@@ -589,6 +609,7 @@ async fn degrade_client_2_bad() -> Result {
589609

590610
#[tokio::test]
591611
#[traced_test]
612+
#[ignore = "not yet passing reliably"]
592613
async fn degrade_client_3_terrible() -> Result {
593614
run_degrade_level(Side::Client, 3).await?.ok();
594615
Ok(())

iroh/tests/patchbay/util.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ async fn spawn_relay(lab: &Lab) -> Result<(RelayMap, AbortOnDropHandle<()>)> {
5757
let relay_v6 = dev_relay.ip6().expect("relay has IPv6");
5858
lab.dns_entry("relay.test", relay_v4.into())?;
5959
lab.dns_entry("relay.test", relay_v6.into())?;
60+
info!(%relay_v4, %relay_v6, "DNS entries for relay.test registered");
6061

6162
let (relay_map_tx, relay_map_rx) = oneshot::channel();
6263
let task_relay = dev_relay.spawn(async move |_ctx| {
@@ -147,13 +148,16 @@ impl Pair {
147148
let server_task = server_device.spawn(|dev| {
148149
let barrier = barrier2;
149150
async move {
150-
let endpoint = endpoint_builder(&dev, relay_map2).bind().await?;
151+
let endpoint = endpoint_builder(&dev, relay_map2).bind().await
152+
.context("server endpoint bind")?;
151153
info!(id=%endpoint.id().fmt_short(), bound_sockets=?endpoint.bound_sockets(), "server endpoint bound");
152154
endpoint.online().await;
153155
info!("endpoint online");
154156
// Send address to client task. Make it a relay-only address, like in the default address lookup services.
155157
addr_tx.send(addr_relay_only(endpoint.addr())).unwrap();
156-
let conn = endpoint.accept().await.unwrap().accept().anyerr()?.await?;
158+
let incoming = endpoint.accept().await.context("server accept incoming")?;
159+
let conn = incoming.accept().anyerr()?.await
160+
.context("server accept handshake")?;
157161
info!(remote=%conn.remote_id().fmt_short(), "accepted, executing run function");
158162
watch_selected_path(&conn);
159163
let res = server_run(dev.clone(), endpoint.clone(), conn).await;
@@ -172,11 +176,13 @@ impl Pair {
172176
})?;
173177
let client_task = client_device.spawn(move |dev| {
174178
async move {
175-
let endpoint = endpoint_builder(&dev, self.relay_map).bind().await?;
179+
let endpoint = endpoint_builder(&dev, self.relay_map).bind().await
180+
.context("client endpoint bind")?;
176181
info!(id=%endpoint.id().fmt_short(), bound_sockets=?endpoint.bound_sockets(), "client endpoint bound");
177182
let addr = addr_rx.await.std_context("server did not send its address")?;
178183
info!(?addr, "connecting to server");
179-
let conn = endpoint.connect(addr, TEST_ALPN).await?;
184+
let conn = endpoint.connect(addr, TEST_ALPN).await
185+
.context("client connect")?;
180186
watch_selected_path(&conn);
181187
info!(remote=%conn.remote_id().fmt_short(), "connected, executing run function");
182188
let res = client_run(dev.clone(), endpoint.clone(), conn).await;
@@ -256,12 +262,16 @@ pub trait PathWatcherExt {
256262

257263
/// Wait until the selected path is a direct (IP) path.
258264
async fn wait_ip(&mut self, timeout: Duration) -> Result<PathInfo> {
259-
self.wait_selected(timeout, PathInfo::is_ip).await
265+
self.wait_selected(timeout, PathInfo::is_ip)
266+
.await
267+
.context("wait_ip")
260268
}
261269

262270
/// Wait until the selected path is a relay path.
263271
async fn wait_relay(&mut self, timeout: Duration) -> Result<PathInfo> {
264-
self.wait_selected(timeout, PathInfo::is_relay).await
272+
self.wait_selected(timeout, PathInfo::is_relay)
273+
.await
274+
.context("wait_relay")
265275
}
266276
}
267277

@@ -289,36 +299,45 @@ impl PathWatcherExt for PathWatcher {
289299
}
290300
})
291301
.await
292-
.anyerr()?
302+
.std_context("wait_selected timed out")?
293303
}
294304
}
295305

296306
/// Opens a bidi stream, sends 8 bytes of data, and waits to receive the same data back.
297307
pub async fn ping_open(conn: &Connection, timeout: Duration) -> Result {
298308
tokio::time::timeout(timeout, async {
299309
let data: [u8; 8] = rand::random();
310+
debug!("open_bi");
300311
let (mut send, mut recv) = conn.open_bi().await.anyerr()?;
312+
debug!("write_all");
301313
send.write_all(&data).await.anyerr()?;
302314
send.finish().anyerr()?;
315+
debug!("read_to_end");
303316
let r = recv.read_to_end(8).await.anyerr()?;
304317
ensure_any!(r == data, "reply matches");
318+
debug!("done");
305319
Ok(())
306320
})
307321
.await
308-
.anyerr()?
322+
.std_context("ping_open timed out")?
309323
}
310324

311325
/// Accepts a bidi stream, reads 8 bytes of data, and sends the same data back.
312326
pub async fn ping_accept(conn: &Connection, timeout: Duration) -> Result {
313327
tokio::time::timeout(timeout, async {
328+
debug!("accept_bi");
314329
let (mut send, mut recv) = conn.accept_bi().await.anyerr()?;
330+
debug!("read_to_end");
315331
let data = recv.read_to_end(8).await.anyerr()?;
332+
debug!("write_all");
316333
send.write_all(&data).await.anyerr()?;
317334
send.finish().anyerr()?;
335+
debug!("done");
318336
Ok(())
319337
})
338+
.instrument(error_span!("ping_accept"))
320339
.await
321-
.anyerr()?
340+
.std_context("ping_accept timed out")?
322341
}
323342

324343
fn watch_selected_path(conn: &Connection) {

0 commit comments

Comments
 (0)