Skip to content

Commit 88292c4

Browse files
committed
[FAB-4854] Harden TestMsgStoreExpiration test
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 <[email protected]>
1 parent b4eef8e commit 88292c4

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

gossip/discovery/discovery_test.go

+22-7
Original file line numberDiff line numberDiff line change
@@ -1206,15 +1206,30 @@ func stopInstances(t *testing.T, instances []*gossipInstance) {
12061206
}
12071207

12081208
func assertMembership(t *testing.T, instances []*gossipInstance, expectedNum int) {
1209-
fullMembership := func() bool {
1210-
for _, inst := range instances {
1211-
if len(inst.GetMembership()) != expectedNum {
1212-
return false
1209+
wg := sync.WaitGroup{}
1210+
wg.Add(len(instances))
1211+
1212+
ctx, cancelation := context.WithTimeout(context.Background(), timeout)
1213+
defer cancelation()
1214+
1215+
for _, inst := range instances {
1216+
go func(ctx context.Context, i *gossipInstance) {
1217+
defer wg.Done()
1218+
for {
1219+
select {
1220+
case <-ctx.Done():
1221+
return
1222+
case <-time.After(timeout / 10):
1223+
if len(i.GetMembership()) == expectedNum {
1224+
return
1225+
}
1226+
}
12131227
}
1214-
}
1215-
return true
1228+
}(ctx, inst)
12161229
}
1217-
waitUntilOrFail(t, fullMembership)
1230+
1231+
wg.Wait()
1232+
assert.NoError(t, ctx.Err(), "Timeout expired!")
12181233
}
12191234

12201235
func portsOfMembers(members []NetworkMember) []int {

0 commit comments

Comments
 (0)