fix(test): only listen on 127.0.0.1 for ephemeral swarm

This resolves an issue where our tests were depending on the number of network interfaces available on the local machine.

Related #4110.

Pull-Request: #4122.


  
Co-Authored-By: Thomas Eizinger <thomas@eizinger.io>
This commit is contained in:
Thomas Eizinger
2023-06-27 03:21:47 +02:00
committed by GitHub
parent e32775d6fb
commit d5475fccde
5 changed files with 32 additions and 6 deletions

View File

@ -148,7 +148,20 @@ async fn run_discovery_test(config: Config) {
async fn create_swarm(config: Config) -> Swarm<Behaviour> {
let mut swarm =
Swarm::new_ephemeral(|key| Behaviour::new(config, key.public().to_peer_id()).unwrap());
swarm.listen().await;
// Manually listen on all interfaces because mDNS only works for non-loopback addresses.
let expected_listener_id = swarm
.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap())
.unwrap();
swarm
.wait(|e| match e {
SwarmEvent::NewListenAddr { listener_id, .. } => {
(listener_id == expected_listener_id).then_some(())
}
_ => None,
})
.await;
swarm
}