@@ -52,3 +52,40 @@ func TestPeerDiscovery(t *testing.T) {
52
52
t .Errorf ("bootstrap address %v is not in node known peers" , bootAddr )
53
53
}
54
54
}
55
+
56
+ func TestRemovalOfUnhealthyPeer (t * testing.T ) {
57
+ wg := new (sync.WaitGroup )
58
+ // Create the peer discovery without staring for the bootstrap node
59
+ bootPeerDisc := createPeerDiscovery (t .Context (), wg , true , false )
60
+ // Start the gRPC server on the bootstrap node
61
+ waitForPeersDiscovery := make (chan struct {})
62
+ grpcStartSvr (t , bootAddr , func (grpcSrv * grpc.Server ) {
63
+ node := rpc .NewNodeSrv (bootPeerDisc , nil )
64
+ rpc .RegisterNodeServer (grpcSrv , node )
65
+
66
+ go func () {
67
+ <- waitForPeersDiscovery
68
+ grpcSrv .Stop ()
69
+ }()
70
+ })
71
+ // Create and start the peer discovery for the new node
72
+ nodePeerDisc := createPeerDiscovery (t .Context (), wg , false , true )
73
+ // Wait for the peer discovery to discover peers
74
+ time .Sleep (150 * time .Millisecond )
75
+ // Verify that the bootstrap node and the new node have discovered each other
76
+
77
+ if ! slices .Contains (bootPeerDisc .Peers (), nodeAddr ) {
78
+ t .Errorf ("node address %v is not in bootstrap known peers" , nodeAddr )
79
+ }
80
+ if ! slices .Contains (nodePeerDisc .Peers (), bootAddr ) {
81
+ t .Errorf ("bootstrap address %v is not in node known peers" , bootAddr )
82
+ }
83
+
84
+ waitForPeersDiscovery <- struct {}{}
85
+ // Wait for the peer discovery to try to discover peers
86
+ time .Sleep (250 * time .Millisecond )
87
+
88
+ if len (nodePeerDisc .Peers ()) != 0 {
89
+ t .Errorf ("node peer discovery should not have any peers after the bootstrap node is stopped" )
90
+ }
91
+ }
0 commit comments