Skip to content

Commit

Permalink
Remove timing assumtions from gossip test
Browse files Browse the repository at this point in the history
Change-Id: Ifde82d756c4bc13cdfa97900ee05eb7d35966814
Signed-off-by: Artem Barger <bartem@il.ibm.com>
  • Loading branch information
C0rWin committed Nov 11, 2016
1 parent d221a6b commit 15e677a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions gossip/gossip/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,17 @@ func TestDissemination(t *testing.T) {
n := 20
msgsCount2Send := 10
boot := newGossipInstance(0, 100)
time.Sleep(time.Duration(2) * time.Second)

peers := make([]Gossip, n)
receivedMessages := make([]int, n)
wg := sync.WaitGroup{}

for i := 1; i <= n; i++ {
pI := newGossipInstance(i, 100, 0)
peers[i - 1] = pI

wg.Add(1)
go func(index int, ch <-chan *proto.GossipMessage) {
wg.Add(1)
defer wg.Done()
for j := 0; j < msgsCount2Send; j++ {
<-ch
Expand All @@ -331,7 +333,7 @@ func TestDissemination(t *testing.T) {
}(i - 1, pI.Accept(acceptData))
}

time.Sleep(time.Duration(10) * time.Second)
waitUntilOrFail(t, checkPeersMembership(peers, n))

for i := 1; i <= msgsCount2Send; i++ {
boot.Gossip(createDataMsg(uint64(i), []byte{}, ""))
Expand Down Expand Up @@ -618,12 +620,22 @@ func waitUntilOrFailBlocking(t *testing.T, f func()) {
assert.Fail(t, "Timeout expired!")
}


func searchInStackTrace(searchTerm string, stack []string) bool {
for _, ste := range stack {
if strings.Index(ste, searchTerm) != -1 {
return true
}
}
return false
}
}

func checkPeersMembership(peers []Gossip, n int) func() bool {
return func() bool {
for _, peer := range peers {
if len(peer.GetPeers()) != n {
return false
}
}
return true
}
}

0 comments on commit 15e677a

Please sign in to comment.