@@ -790,7 +790,96 @@ func TestFilterOutLocalhost(t *testing.T) {
790
790
assert .NotEqual (t , endpoints [2 ], endpoints [0 ])
791
791
}
792
792
793
+ func TestMsgStoreExpiration (t * testing.T ) {
794
+ t .Parallel ()
795
+ nodeNum := 4
796
+ bootPeers := []string {bootPeer (12611 ), bootPeer (12612 )}
797
+ instances := []* gossipInstance {}
798
+
799
+ inst := createDiscoveryInstance (12611 , "d1" , bootPeers )
800
+ instances = append (instances , inst )
801
+
802
+ inst = createDiscoveryInstance (12612 , "d2" , bootPeers )
803
+ instances = append (instances , inst )
804
+
805
+ for i := 3 ; i <= nodeNum ; i ++ {
806
+ id := fmt .Sprintf ("d%d" , i )
807
+ inst = createDiscoveryInstance (12610 + i , id , bootPeers )
808
+ instances = append (instances , inst )
809
+ }
810
+
811
+ assertMembership (t , instances , nodeNum - 1 )
812
+
813
+ waitUntilOrFailBlocking (t , instances [nodeNum - 1 ].Stop )
814
+ waitUntilOrFailBlocking (t , instances [nodeNum - 2 ].Stop )
815
+
816
+ assertMembership (t , instances , nodeNum - 3 )
817
+
818
+ checkMessages := func () bool {
819
+ for _ , inst := range instances [:len (instances )- 2 ] {
820
+ for _ , downInst := range instances [len (instances )- 2 :] {
821
+ downCastInst := inst .Discovery .(* gossipDiscoveryImpl )
822
+ downCastInst .lock .RLock ()
823
+ if _ , exist := downCastInst .aliveLastTS [string (downInst .Discovery .(* gossipDiscoveryImpl ).self .PKIid )]; exist {
824
+ downCastInst .lock .RUnlock ()
825
+ return false
826
+ }
827
+ if _ , exist := downCastInst .deadLastTS [string (downInst .Discovery .(* gossipDiscoveryImpl ).self .PKIid )]; exist {
828
+ downCastInst .lock .RUnlock ()
829
+ return false
830
+ }
831
+ if _ , exist := downCastInst .id2Member [string (downInst .Discovery .(* gossipDiscoveryImpl ).self .PKIid )]; exist {
832
+ downCastInst .lock .RUnlock ()
833
+ return false
834
+ }
835
+ if downCastInst .aliveMembership .MsgByID (downInst .Discovery .(* gossipDiscoveryImpl ).self .PKIid ) != nil {
836
+ downCastInst .lock .RUnlock ()
837
+ return false
838
+ }
839
+ if downCastInst .deadMembership .MsgByID (downInst .Discovery .(* gossipDiscoveryImpl ).self .PKIid ) != nil {
840
+ downCastInst .lock .RUnlock ()
841
+ return false
842
+ }
843
+ downCastInst .lock .RUnlock ()
844
+ }
845
+ }
846
+ return true
847
+ }
848
+
849
+ waitUntilTimeoutOrFail (t , checkMessages , timeout * 2 )
850
+
851
+ assertMembership (t , instances [:len (instances )- 2 ], nodeNum - 3 )
852
+
853
+ peerToResponse := & NetworkMember {
854
+ Metadata : []byte {},
855
+ PKIid : []byte (fmt .Sprintf ("localhost:%d" , 12612 )),
856
+ Endpoint : fmt .Sprintf ("localhost:%d" , 12612 ),
857
+ InternalEndpoint : fmt .Sprintf ("localhost:%d" , 12612 ),
858
+ }
859
+
860
+ downCastInstance := instances [0 ].Discovery .(* gossipDiscoveryImpl )
861
+ memResp := downCastInstance .createMembershipResponse (peerToResponse )
862
+
863
+ downCastInstance .comm .SendToPeer (peerToResponse , (& proto.GossipMessage {
864
+ Tag : proto .GossipMessage_EMPTY ,
865
+ Nonce : uint64 (0 ),
866
+ Content : & proto.GossipMessage_MemRes {
867
+ MemRes : memResp ,
868
+ },
869
+ }).NoopSign ())
870
+
871
+ time .Sleep (getAliveExpirationTimeout ())
872
+
873
+ assert .True (t , checkMessages (), "Validating lost message with already dead and expired nodes failed" )
874
+
875
+ stopInstances (t , instances [:len (instances )- 2 ])
876
+ }
877
+
793
878
func waitUntilOrFail (t * testing.T , pred func () bool ) {
879
+ waitUntilTimeoutOrFail (t , pred , timeout )
880
+ }
881
+
882
+ func waitUntilTimeoutOrFail (t * testing.T , pred func () bool , timeout time.Duration ) {
794
883
start := time .Now ()
795
884
limit := start .UnixNano () + timeout .Nanoseconds ()
796
885
for time .Now ().UnixNano () < limit {
0 commit comments