@@ -3,8 +3,8 @@ use std::time::Duration;
3
3
use node:: {
4
4
event_source:: Event ,
5
5
p2p:: {
6
- connection:: outgoing:: P2pConnectionOutgoingInitOpts , P2pEvent , P2pPeerState , P2pPeerStatus ,
7
- P2pState , PeerId ,
6
+ connection:: outgoing:: P2pConnectionOutgoingInitOpts , P2pConnectionEvent , P2pEvent ,
7
+ P2pPeerState , P2pPeerStatus , P2pState , PeerId ,
8
8
} ,
9
9
} ;
10
10
@@ -131,7 +131,10 @@ impl AllNodesConnectionsAreSymmetric {
131
131
. await
132
132
. unwrap ( )
133
133
{
134
- assert ! ( std:: time:: Instant :: now( ) < timeout, "cluster should stop generating events" ) ;
134
+ assert ! (
135
+ std:: time:: Instant :: now( ) < timeout,
136
+ "cluster should stop generating events"
137
+ ) ;
135
138
}
136
139
137
140
// Check that for each peer, if it is in the node's peer list, then the node is in the peer's peer list
@@ -324,7 +327,51 @@ impl MaxNumberOfPeers {
324
327
. filter_map ( |peer| peer. state ( ) . p2p . peers . get ( & nut_peer_id) )
325
328
. filter ( |state| matches ! ( state. status, P2pPeerStatus :: Ready ( ..) ) )
326
329
. count ( ) ;
327
- assert ! ( peers_connected <= MAX . into( ) , "peers connections to the node exceed the max number of connections: {peers_connected}" ) ;
330
+ assert ! (
331
+ peers_connected <= MAX . into( ) ,
332
+ "peers connections to the node exceed the max number of connections: {peers_connected}"
333
+ ) ;
334
+ }
335
+ }
336
+
337
+ /// Two nodes should stay connected for a long period of time.
338
+ #[ derive( documented:: Documented , Default , Clone , Copy ) ]
339
+ pub struct ConnectionStability ;
340
+
341
+ impl ConnectionStability {
342
+ pub async fn run < ' cluster > ( self , runner : ClusterRunner < ' cluster > ) {
343
+ const CONNECTED_TIME_SEC : u64 = 1 * 60 ;
344
+ let mut driver = Driver :: new ( runner) ;
345
+
346
+ let ( node1, _) = driver. add_rust_node ( RustNodeTestingConfig :: berkeley_default ( ) . max_peers ( 1 ) ) ;
347
+ let ( node2, _) = driver. add_rust_node ( RustNodeTestingConfig :: berkeley_default ( ) . max_peers ( 1 ) ) ;
348
+
349
+ assert ! (
350
+ wait_for_nodes_listening_on_localhost( & mut driver, Duration :: from_secs( 30 ) , [ node2] )
351
+ . await
352
+ . unwrap( ) ,
353
+ "nodes should be listening"
354
+ ) ;
355
+
356
+ driver
357
+ . exec_step ( crate :: scenario:: ScenarioStep :: ConnectNodes {
358
+ dialer : node1,
359
+ listener : crate :: scenario:: ListenerNode :: Rust ( node2) ,
360
+ } )
361
+ . await
362
+ . expect ( "connect event should be dispatched" ) ;
363
+
364
+ // Run the cluster while there are events
365
+ let disconnected = driver
366
+ . run_until ( Duration :: from_secs ( CONNECTED_TIME_SEC ) , |_, event, _| {
367
+ matches ! (
368
+ event,
369
+ Event :: P2p ( P2pEvent :: Connection ( P2pConnectionEvent :: Closed ( _) ) )
370
+ )
371
+ } )
372
+ . await
373
+ . unwrap ( ) ;
328
374
375
+ assert ! ( !disconnected, "there shouldn't be a disconnection" ) ;
329
376
}
330
377
}
0 commit comments