@@ -1891,8 +1891,10 @@ mod tests {
1891
1891
/// calls should be registered.
1892
1892
#[ test]
1893
1893
fn test_connect_disconnect_ban ( ) {
1894
+ let _ = env_logger:: try_init ( ) ;
1895
+
1894
1896
// Since the test does not try to open any substreams, we can
1895
- // use the dummy protocols handler.
1897
+ // use keep alive protocols handler.
1896
1898
let handler_proto = keep_alive:: ConnectionHandler ;
1897
1899
1898
1900
let mut swarm1 = new_test_swarm :: < _ , ( ) > ( handler_proto. clone ( ) ) . build ( ) ;
@@ -1906,6 +1908,7 @@ mod tests {
1906
1908
1907
1909
let swarm1_id = * swarm1. local_peer_id ( ) ;
1908
1910
1911
+ #[ derive( Debug ) ]
1909
1912
enum Stage {
1910
1913
/// Waiting for the peers to connect. Banning has not occurred.
1911
1914
Connecting ,
@@ -1950,25 +1953,31 @@ mod tests {
1950
1953
{
1951
1954
// Setup to test that new connections of banned peers are not reported.
1952
1955
swarm1. dial ( addr2. clone ( ) ) . unwrap ( ) ;
1956
+ s1_expected_conns += 1 ;
1953
1957
stage = Stage :: BannedDial ;
1954
1958
}
1955
1959
}
1956
1960
Stage :: BannedDial => {
1957
- // The banned connection was established. Check that it was not reported to
1958
- // the behaviour of the banning swarm.
1959
- assert_eq ! (
1960
- swarm2. behaviour. on_connection_established. len( ) ,
1961
- s2_expected_conns,
1962
- "No additional closed connections should be reported for the banned peer"
1963
- ) ;
1961
+ if swarm1. behaviour . assert_disconnected ( s1_expected_conns, 2 ) {
1962
+ // The banned connection was established. Given the ban, swarm2 closed the
1963
+ // connection. Check that it was not reported to the behaviour of the
1964
+ // banning swarm.
1965
+ assert_eq ! (
1966
+ swarm2. behaviour. on_connection_established. len( ) ,
1967
+ s2_expected_conns,
1968
+ "No additional closed connections should be reported for the banned peer"
1969
+ ) ;
1964
1970
1965
- // Setup to test that the banned connection is not reported upon closing
1966
- // even if the peer is unbanned.
1967
- swarm2. unban_peer_id ( swarm1_id) ;
1968
- stage = Stage :: Unbanned ;
1971
+ // Setup to test that the banned connection is not reported upon closing
1972
+ // even if the peer is unbanned.
1973
+ swarm2. unban_peer_id ( swarm1_id) ;
1974
+ stage = Stage :: Unbanned ;
1975
+ }
1969
1976
}
1970
1977
Stage :: Unbanned => {
1971
- if swarm2. network_info ( ) . num_peers ( ) == 0 {
1978
+ if swarm1. network_info ( ) . num_peers ( ) == 0
1979
+ && swarm2. network_info ( ) . num_peers ( ) == 0
1980
+ {
1972
1981
// The banned connection has closed. Check that it was not reported.
1973
1982
assert_eq ! (
1974
1983
swarm2. behaviour. on_connection_closed. len( ) , s2_expected_conns,
0 commit comments