fn run_gossip_topo<F>(topo: F)
where
    F: Fn(&Vec<(Arc<RwLock<ClusterInfo>>, Ncp, UdpSocket)>) -> (),
{
    let num: usize = 5;
    let exit = Arc::new(AtomicBool::new(false));
    let listen: Vec<_> = (0..num).map(|_| test_node(exit.clone())).collect();
    topo(&listen);
    let mut done = true;
    for i in 0..(num * 32) {
        done = false;
        trace!("round {}", i);
        for (c, _, _) in &listen {
            if num == c.read().unwrap().convergence() as usize {
                done = true;
                break;
            }
        }
        //at least 1 node converged
        if done == true {
            break;
        }
        sleep(Duration::new(1, 0));
    }
    exit.store(true, Ordering::Relaxed);
    for (c, dr, _) in listen {
        dr.join().unwrap();
        // make it clear what failed
        // protocol is to chatty, updates should stop after everyone receives `num`
        assert!(c.read().unwrap().update_index <= num as u64);
        // protocol is not chatty enough, everyone should get `num` entries
        assert_eq!(c.read().unwrap().table.len(), num);
    }
    assert!(done);
}
/// Test that the network converges.
/// Run until every node in the network has a full NodeInfo set.
/// Check that nodes stop sending updates after all the NodeInfo has been shared.
/// tests that actually use this function are below
Test that the network converges.
Run until every node in the network has a full NodeInfo set.
Check that nodes stop sending updates after all the NodeInfo has been shared.
tests that actually use this function are below
Test that the network converges . Run until every node in the network has a full NodeInfo set . Check that nodes stop sending updates after all the NodeInfo has been shared . tests that actually use this function are below
fn run_gossip_topo<F>(topo: F)
where
    F: Fn(&Vec<(Arc<RwLock<ClusterInfo>>, Ncp, UdpSocket)>) -> (),
{
    let num: usize = 5;
    let exit = Arc::new(AtomicBool::new(false));
    let listen: Vec<_> = (0..num).map(|_| test_node(exit.clone())).collect();
    topo(&listen);
    let mut done = true;
    for i in 0..(num * 32) {
        done = false;
        trace!("round {}", i);
        for (c, _, _) in &listen {
            if num == c.read().unwrap().convergence() as usize {
                done = true;
                break;
            }
        }
        //at least 1 node converged
        if done == true {
            break;
        }
        sleep(Duration::new(1, 0));
    }
    exit.store(true, Ordering::Relaxed);
    for (c, dr, _) in listen {
        dr.join().unwrap();
        // make it clear what failed
        // protocol is to chatty, updates should stop after everyone receives `num`
        assert!(c.read().unwrap().update_index <= num as u64);
        // protocol is not chatty enough, everyone should get `num` entries
        assert_eq!(c.read().unwrap().table.len(), num);
    }
    assert!(done);
}
fn run_gossip_topo < F > ( topo : F ) where F : Fn ( & Vec < ( Arc < RwLock < ClusterInfo > > , Ncp , UdpSocket ) > ) -> ( ) , { let num : usize = 5 ; let exit = Arc :: new ( AtomicBool :: new ( false ) ) ; let listen : Vec < _ > = ( 0 .. num ) . map ( | _ | test_node ( exit . clone ( ) ) ) . collect ( ) ; topo ( & listen ) ; let mut done = true ; for i in 0 .. ( num * 32 ) { done = false ; trace ! ( " " i ) ; for ( c , _ , _ ) in & listen { if num == c . read ( ) . unwrap ( ) . convergence ( ) as usize { done = true ; break ; } } //at least 1 node converged if done == true { break ; } sleep ( Duration :: new ( 1 , 0 ) ) ; } exit . store ( true , Ordering :: Relaxed ) ; for ( c , dr , _ ) in listen { dr . join ( ) . unwrap ( ) ; // make it clear what failed // protocol is to chatty, updates should stop after everyone receives `num` assert ! ( c read ( ) unwrap ( ) update_index num as u64 ) ; // protocol is not chatty enough, everyone should get `num` entries assert_eq ! ( c read ( ) unwrap ( ) table len ( ) num ) ; } assert ! ( done ) ; }
Test that the network converges.
Test that the network converges .
topo
F
topo
F