Skip to content

Commit a25ab7e

Browse files
refactor(gossipsub): use dummy handler instead of calling new_handler (#3384)
The gossipsub tests are calling lifecycle functions of the `NetworkBehaviour` that aren't meant to be called outside of `Swarm`. This already surfaced as a problem in #3327 and it is coming up again in #3254 where `new_handler` gets deprecated. Try to mitigate that by constructing a dummy handler instead. Functionally, there is no difference as in both cases, the given handler has never seen a connection.
1 parent 62c0532 commit a25ab7e

File tree

1 file changed

+9
-2
lines changed
  • protocols/gossipsub/src/behaviour

1 file changed

+9
-2
lines changed

protocols/gossipsub/src/behaviour/tests.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use async_std::net::Ipv4Addr;
3333
use byteorder::{BigEndian, ByteOrder};
3434
use libp2p_core::{ConnectedPoint, Endpoint};
3535
use rand::Rng;
36+
use std::borrow::Cow;
3637
use std::collections::hash_map::DefaultHasher;
3738
use std::hash::{Hash, Hasher};
3839
use std::thread::sleep;
@@ -265,15 +266,21 @@ where
265266
role_override: Endpoint::Dialer,
266267
}; // this is not relevant
267268
// peer_connections.connections should never be empty.
269+
268270
let mut active_connections = peer_connections.connections.len();
269271
for connection_id in peer_connections.connections.clone() {
270-
let handler = gs.new_handler();
271272
active_connections = active_connections.checked_sub(1).unwrap();
273+
274+
let dummy_handler = GossipsubHandler::new(
275+
ProtocolConfig::new(Cow::from(""), None, 0, ValidationMode::None, false),
276+
Duration::ZERO,
277+
);
278+
272279
gs.on_swarm_event(FromSwarm::ConnectionClosed(ConnectionClosed {
273280
peer_id: *peer_id,
274281
connection_id,
275282
endpoint: &fake_endpoint,
276-
handler,
283+
handler: dummy_handler,
277284
remaining_established: active_connections,
278285
}));
279286
}

0 commit comments

Comments
 (0)