@@ -1891,8 +1891,10 @@ mod tests {
18911891 /// calls should be registered.
18921892 #[ test]
18931893 fn test_connect_disconnect_ban ( ) {
1894+ let _ = env_logger:: try_init ( ) ;
1895+
18941896 // Since the test does not try to open any substreams, we can
1895- // use the dummy protocols handler.
1897+ // use keep alive protocols handler.
18961898 let handler_proto = keep_alive:: ConnectionHandler ;
18971899
18981900 let mut swarm1 = new_test_swarm :: < _ , ( ) > ( handler_proto. clone ( ) ) . build ( ) ;
@@ -1906,6 +1908,7 @@ mod tests {
19061908
19071909 let swarm1_id = * swarm1. local_peer_id ( ) ;
19081910
1911+ #[ derive( Debug ) ]
19091912 enum Stage {
19101913 /// Waiting for the peers to connect. Banning has not occurred.
19111914 Connecting ,
@@ -1950,25 +1953,31 @@ mod tests {
19501953 {
19511954 // Setup to test that new connections of banned peers are not reported.
19521955 swarm1. dial ( addr2. clone ( ) ) . unwrap ( ) ;
1956+ s1_expected_conns += 1 ;
19531957 stage = Stage :: BannedDial ;
19541958 }
19551959 }
19561960 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+ ) ;
19641970
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+ }
19691976 }
19701977 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+ {
19721981 // The banned connection has closed. Check that it was not reported.
19731982 assert_eq ! (
19741983 swarm2. behaviour. on_connection_closed. len( ) , s2_expected_conns,
0 commit comments