@@ -314,15 +314,17 @@ func TestDissemination(t *testing.T) {
314
314
n := 20
315
315
msgsCount2Send := 10
316
316
boot := newGossipInstance (0 , 100 )
317
- time . Sleep ( time . Duration ( 2 ) * time . Second )
317
+
318
318
peers := make ([]Gossip , n )
319
319
receivedMessages := make ([]int , n )
320
320
wg := sync.WaitGroup {}
321
+
321
322
for i := 1 ; i <= n ; i ++ {
322
323
pI := newGossipInstance (i , 100 , 0 )
323
324
peers [i - 1 ] = pI
325
+
326
+ wg .Add (1 )
324
327
go func (index int , ch <- chan * proto.GossipMessage ) {
325
- wg .Add (1 )
326
328
defer wg .Done ()
327
329
for j := 0 ; j < msgsCount2Send ; j ++ {
328
330
<- ch
@@ -331,7 +333,7 @@ func TestDissemination(t *testing.T) {
331
333
}(i - 1 , pI .Accept (acceptData ))
332
334
}
333
335
334
- time . Sleep ( time . Duration ( 10 ) * time . Second )
336
+ waitUntilOrFail ( t , checkPeersMembership ( peers , n ) )
335
337
336
338
for i := 1 ; i <= msgsCount2Send ; i ++ {
337
339
boot .Gossip (createDataMsg (uint64 (i ), []byte {}, "" ))
@@ -618,12 +620,22 @@ func waitUntilOrFailBlocking(t *testing.T, f func()) {
618
620
assert .Fail (t , "Timeout expired!" )
619
621
}
620
622
621
-
622
623
func searchInStackTrace (searchTerm string , stack []string ) bool {
623
624
for _ , ste := range stack {
624
625
if strings .Index (ste , searchTerm ) != - 1 {
625
626
return true
626
627
}
627
628
}
628
629
return false
629
- }
630
+ }
631
+
632
+ func checkPeersMembership (peers []Gossip , n int ) func () bool {
633
+ return func () bool {
634
+ for _ , peer := range peers {
635
+ if len (peer .GetPeers ()) != n {
636
+ return false
637
+ }
638
+ }
639
+ return true
640
+ }
641
+ }
0 commit comments