Skip to content

Commit

Permalink
[FAB-4854] Harden TestMsgStoreExpiration test
Browse files Browse the repository at this point in the history
Refactor TestMsgStoreExpiration test to assert for membership while
leveraging context with timeout and verify membership simultaneously
rather than interating over peer instances to check for required number
of nodes in view.

Change-Id: Ib165be64b3fd7977356b87b8ee4d978eb0da91cc
Signed-off-by: Artem Barger <bartem@il.ibm.com>
  • Loading branch information
C0rWin committed Jun 18, 2017
1 parent b4eef8e commit 88292c4
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions gossip/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,15 +1206,30 @@ func stopInstances(t *testing.T, instances []*gossipInstance) {
}

func assertMembership(t *testing.T, instances []*gossipInstance, expectedNum int) {
fullMembership := func() bool {
for _, inst := range instances {
if len(inst.GetMembership()) != expectedNum {
return false
wg := sync.WaitGroup{}
wg.Add(len(instances))

ctx, cancelation := context.WithTimeout(context.Background(), timeout)
defer cancelation()

for _, inst := range instances {
go func(ctx context.Context, i *gossipInstance) {
defer wg.Done()
for {
select {
case <-ctx.Done():
return
case <-time.After(timeout / 10):
if len(i.GetMembership()) == expectedNum {
return
}
}
}
}
return true
}(ctx, inst)
}
waitUntilOrFail(t, fullMembership)

wg.Wait()
assert.NoError(t, ctx.Err(), "Timeout expired!")
}

func portsOfMembers(members []NetworkMember) []int {
Expand Down

0 comments on commit 88292c4

Please sign in to comment.