diff --git a/pr/3619/docs/src/iroh/magicsock/transports/relay/actor.rs.html b/pr/3619/docs/src/iroh/magicsock/transports/relay/actor.rs.html index 122a06e17a..9bed2ffb46 100644 --- a/pr/3619/docs/src/iroh/magicsock/transports/relay/actor.rs.html +++ b/pr/3619/docs/src/iroh/magicsock/transports/relay/actor.rs.html @@ -1466,98 +1466,99 @@ 1466 1467 #[tokio::test] 1468 #[traced_test] -1469 async fn test_active_relay_inactive() -> Result { -1470 let (_relay_map, relay_url, _server) = test_utils::run_relay_server().await?; -1471 -1472 let secret_key = SecretKey::from_bytes(&[1u8; 32]); -1473 let (datagram_recv_tx, _datagram_recv_rx) = mpsc::channel(16); -1474 let (_send_datagram_tx, send_datagram_rx) = mpsc::channel(16); -1475 let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8); -1476 let (inbox_tx, inbox_rx) = mpsc::channel(16); -1477 let cancel_token = CancellationToken::new(); -1478 let mut task = start_active_relay_actor( -1479 secret_key, -1480 cancel_token.clone(), -1481 relay_url, -1482 prio_inbox_rx, -1483 inbox_rx, -1484 send_datagram_rx, -1485 datagram_recv_tx, -1486 info_span!("actor-under-test"), -1487 ); -1488 -1489 // Wait until the actor is connected to the relay server. -1490 tokio::time::timeout(Duration::from_millis(200), async { -1491 loop { -1492 let (tx, rx) = oneshot::channel(); -1493 inbox_tx.send(ActiveRelayMessage::PingServer(tx)).await.ok(); -1494 if tokio::time::timeout(Duration::from_millis(100), rx) -1495 .await -1496 .map(|resp| resp.is_ok()) -1497 .unwrap_or_default() -1498 { -1499 break; -1500 } -1501 } -1502 }) -1503 .await -1504 .std_context("timeout")?; -1505 -1506 // From now on, we pause time -1507 tokio::time::pause(); -1508 // We now have an idling ActiveRelayActor. If we advance time just a little it -1509 // should stay alive. -1510 info!("Stepping time forwards by RELAY_INACTIVE_CLEANUP_TIME / 2"); -1511 tokio::time::advance(RELAY_INACTIVE_CLEANUP_TIME / 2).await; -1512 -1513 assert!( -1514 tokio::time::timeout(Duration::from_millis(100), &mut task) -1515 .await -1516 .is_err(), -1517 "actor task terminated" -1518 ); -1519 -1520 // If we advance time a lot it should finish. -1521 info!("Stepping time forwards by RELAY_INACTIVE_CLEANUP_TIME"); -1522 tokio::time::advance(RELAY_INACTIVE_CLEANUP_TIME).await; -1523 assert!( -1524 tokio::time::timeout(Duration::from_millis(1000), task) -1525 .await -1526 .is_ok(), -1527 "actor task still running" -1528 ); -1529 -1530 tokio::time::resume(); -1531 cancel_token.cancel(); -1532 Ok(()) -1533 } -1534 -1535 #[tokio::test] -1536 async fn test_ping_tracker() { -1537 tokio::time::pause(); -1538 let mut tracker = PingTracker::default(); -1539 -1540 let ping0 = tracker.new_ping(); -1541 -1542 let res = tokio::time::timeout(Duration::from_secs(1), tracker.timeout()).await; -1543 assert!(res.is_err(), "no ping timeout has elapsed yet"); -1544 -1545 tracker.pong_received(ping0); -1546 let res = tokio::time::timeout(Duration::from_secs(10), tracker.timeout()).await; -1547 assert!(res.is_err(), "ping completed before timeout"); -1548 -1549 let _ping1 = tracker.new_ping(); -1550 -1551 let res = tokio::time::timeout(Duration::from_secs(10), tracker.timeout()).await; -1552 assert!(res.is_ok(), "ping timeout should have happened"); -1553 -1554 let _ping2 = tracker.new_ping(); -1555 -1556 tokio::time::sleep(Duration::from_secs(10)).await; -1557 let res = tokio::time::timeout(Duration::from_millis(1), tracker.timeout()).await; -1558 assert!(res.is_ok(), "ping timeout happened in the past"); -1559 -1560 let res = tokio::time::timeout(Duration::from_secs(10), tracker.timeout()).await; -1561 assert!(res.is_err(), "ping timeout should only happen once"); -1562 } -1563} \ No newline at end of file +1469 #[ignore = "flaky"] +1470 async fn test_active_relay_inactive() -> Result { +1471 let (_relay_map, relay_url, _server) = test_utils::run_relay_server().await?; +1472 +1473 let secret_key = SecretKey::from_bytes(&[1u8; 32]); +1474 let (datagram_recv_tx, _datagram_recv_rx) = mpsc::channel(16); +1475 let (_send_datagram_tx, send_datagram_rx) = mpsc::channel(16); +1476 let (_prio_inbox_tx, prio_inbox_rx) = mpsc::channel(8); +1477 let (inbox_tx, inbox_rx) = mpsc::channel(16); +1478 let cancel_token = CancellationToken::new(); +1479 let mut task = start_active_relay_actor( +1480 secret_key, +1481 cancel_token.clone(), +1482 relay_url, +1483 prio_inbox_rx, +1484 inbox_rx, +1485 send_datagram_rx, +1486 datagram_recv_tx, +1487 info_span!("actor-under-test"), +1488 ); +1489 +1490 // Wait until the actor is connected to the relay server. +1491 tokio::time::timeout(Duration::from_millis(200), async { +1492 loop { +1493 let (tx, rx) = oneshot::channel(); +1494 inbox_tx.send(ActiveRelayMessage::PingServer(tx)).await.ok(); +1495 if tokio::time::timeout(Duration::from_millis(100), rx) +1496 .await +1497 .map(|resp| resp.is_ok()) +1498 .unwrap_or_default() +1499 { +1500 break; +1501 } +1502 } +1503 }) +1504 .await +1505 .std_context("timeout")?; +1506 +1507 // From now on, we pause time +1508 tokio::time::pause(); +1509 // We now have an idling ActiveRelayActor. If we advance time just a little it +1510 // should stay alive. +1511 info!("Stepping time forwards by RELAY_INACTIVE_CLEANUP_TIME / 2"); +1512 tokio::time::advance(RELAY_INACTIVE_CLEANUP_TIME / 2).await; +1513 +1514 assert!( +1515 tokio::time::timeout(Duration::from_millis(100), &mut task) +1516 .await +1517 .is_err(), +1518 "actor task terminated" +1519 ); +1520 +1521 // If we advance time a lot it should finish. +1522 info!("Stepping time forwards by RELAY_INACTIVE_CLEANUP_TIME"); +1523 tokio::time::advance(RELAY_INACTIVE_CLEANUP_TIME).await; +1524 assert!( +1525 tokio::time::timeout(Duration::from_millis(1000), task) +1526 .await +1527 .is_ok(), +1528 "actor task still running" +1529 ); +1530 +1531 tokio::time::resume(); +1532 cancel_token.cancel(); +1533 Ok(()) +1534 } +1535 +1536 #[tokio::test] +1537 async fn test_ping_tracker() { +1538 tokio::time::pause(); +1539 let mut tracker = PingTracker::default(); +1540 +1541 let ping0 = tracker.new_ping(); +1542 +1543 let res = tokio::time::timeout(Duration::from_secs(1), tracker.timeout()).await; +1544 assert!(res.is_err(), "no ping timeout has elapsed yet"); +1545 +1546 tracker.pong_received(ping0); +1547 let res = tokio::time::timeout(Duration::from_secs(10), tracker.timeout()).await; +1548 assert!(res.is_err(), "ping completed before timeout"); +1549 +1550 let _ping1 = tracker.new_ping(); +1551 +1552 let res = tokio::time::timeout(Duration::from_secs(10), tracker.timeout()).await; +1553 assert!(res.is_ok(), "ping timeout should have happened"); +1554 +1555 let _ping2 = tracker.new_ping(); +1556 +1557 tokio::time::sleep(Duration::from_secs(10)).await; +1558 let res = tokio::time::timeout(Duration::from_millis(1), tracker.timeout()).await; +1559 assert!(res.is_ok(), "ping timeout happened in the past"); +1560 +1561 let res = tokio::time::timeout(Duration::from_secs(10), tracker.timeout()).await; +1562 assert!(res.is_err(), "ping timeout should only happen once"); +1563 } +1564} \ No newline at end of file