Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protocols/autonat: fix flaky test #2480

Merged
merged 17 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions protocols/autonat/tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ async fn test_auto_probe() {
other => panic!("Unexpected behaviour event: {:?}.", other),
};

let mut has_received_response = false;
// Expect inbound dial from server.
loop {
match client.select_next_some().await {
Expand All @@ -198,19 +199,34 @@ async fn test_auto_probe() {
assert_eq!(peer_id, server_id);
break;
}
SwarmEvent::Behaviour(Event::OutboundProbe(OutboundProbeEvent::Response {
probe_id,
peer,
..
})) => {
assert_eq!(peer, server_id);
assert_eq!(probe_id, id);
has_received_response = true;
}
SwarmEvent::IncomingConnection { .. }
| SwarmEvent::NewListenAddr { .. }
| SwarmEvent::ExpiredListenAddr { .. } => {}
other => panic!("Unexpected swarm event: {:?}.", other),
}
}

match next_event(&mut client).await {
Event::OutboundProbe(OutboundProbeEvent::Response { probe_id, peer, .. }) => {
assert_eq!(peer, server_id);
assert_eq!(probe_id, id);
if !has_received_response {
match client.select_next_some().await {
SwarmEvent::Behaviour(Event::OutboundProbe(OutboundProbeEvent::Response {
probe_id,
peer,
..
})) => {
assert_eq!(peer, server_id);
assert_eq!(probe_id, id);
}
other => panic!("Unexpected swarm event: {:?}.", other),
}
other => panic!("Unexpected behaviour event: {:?}.", other),
}

// Expect to flip status to public
Expand Down
7 changes: 3 additions & 4 deletions protocols/autonat/tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ async fn spawn_client(
let (tx, rx) = oneshot::channel();
async_std::task::spawn(async move {
let mut client = init_swarm(Config {
boot_delay: Duration::from_millis(100),
refresh_interval: Duration::from_millis(100),
retry_interval: Duration::from_millis(200),
boot_delay: Duration::from_secs(1),
retry_interval: Duration::from_secs(1),
throttle_server_period: Duration::ZERO,
..Default::default()
})
Expand All @@ -98,7 +97,7 @@ async fn spawn_client(
}
}
if add_dummy_external_addr {
let dummy_addr: Multiaddr = "/ip4/127.0.0.1/tcp/42".parse().unwrap();
let dummy_addr: Multiaddr = "/ip4/127.0.0.1/tcp/12345".parse().unwrap();
client.add_external_address(dummy_addr, AddressScore::Infinite);
}
tx.send((peer_id, addr)).unwrap();
Expand Down