Skip to content

Commit 1db469b

Browse files
committed
[FAB-14118] fix BatchingOfStateRequest flaky test
Remove timeout from test to suppress effect of scheduling on the tests assertions. Change-Id: Ida34608ceff464ed5be66a65400f4307b1d6d6e5 Signed-off-by: Artem Barger <bartem@il.ibm.com>
1 parent 637634e commit 1db469b

File tree

1 file changed

+28
-48
lines changed

1 file changed

+28
-48
lines changed

gossip/state/state_test.go

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,65 +1171,45 @@ func TestNewGossipStateProvider_BatchingOfStateRequest(t *testing.T) {
11711171
}
11721172
_, peerCh := peer.g.Accept(naiveStateMsgPredicate, true)
11731173

1174-
messageCh := make(chan struct{})
1175-
stopWaiting := make(chan struct{})
1174+
wg := sync.WaitGroup{}
1175+
wg.Add(expectedMessagesCnt)
11761176

11771177
// Number of submitted messages is defAntiEntropyBatchSize + 5, therefore
11781178
// expected number of batches is expectedMessagesCnt = 2. Following go routine
11791179
// makes sure it receives expected amount of messages and sends signal of success
11801180
// to continue the test
1181-
go func(expected int) {
1182-
cnt := 0
1183-
for cnt < expected {
1184-
select {
1185-
case <-peerCh:
1186-
{
1187-
cnt++
1188-
}
1189-
1190-
case <-stopWaiting:
1191-
{
1192-
return
1193-
}
1194-
}
1181+
go func() {
1182+
for count := 0; count < expectedMessagesCnt; count++ {
1183+
<-peerCh
1184+
wg.Done()
11951185
}
1186+
}()
11961187

1197-
messageCh <- struct{}{}
1198-
}(expectedMessagesCnt)
1188+
// Once we got message which indicate of two batches being received,
1189+
// making sure messages indeed committed.
1190+
waitUntilTrueOrTimeout(t, func() bool {
1191+
if len(peer.g.PeersOfChannel(common.ChainID(util.GetTestChainID()))) != 1 {
1192+
t.Log("Peer discovery has not finished yet")
1193+
return false
1194+
}
1195+
t.Log("All peer discovered each other!!!")
1196+
return true
1197+
}, 30*time.Second)
11991198

12001199
// Waits for message which indicates that expected number of message batches received
12011200
// otherwise timeouts after 2 * defAntiEntropyInterval + 1 seconds
1202-
select {
1203-
case <-messageCh:
1204-
{
1205-
// Once we got message which indicate of two batches being received,
1206-
// making sure messages indeed committed.
1207-
waitUntilTrueOrTimeout(t, func() bool {
1208-
if len(peer.g.PeersOfChannel(common.ChainID(util.GetTestChainID()))) != 1 {
1209-
t.Log("Peer discovery has not finished yet")
1210-
return false
1211-
}
1212-
t.Log("All peer discovered each other!!!")
1213-
return true
1214-
}, 30*time.Second)
1215-
1216-
t.Log("Waiting for all blocks to arrive.")
1217-
waitUntilTrueOrTimeout(t, func() bool {
1218-
t.Log("Trying to see all peers get all blocks")
1219-
height, err := peer.commit.LedgerHeight()
1220-
if height != uint64(msgCount+1) || err != nil {
1221-
return false
1222-
}
1223-
t.Log("All peers have same ledger height!!!")
1224-
return true
1225-
}, 60*time.Second)
1226-
}
1227-
case <-time.After(defAntiEntropyInterval*2 + time.Second*1):
1228-
{
1229-
close(stopWaiting)
1230-
t.Fatal("Expected to receive two batches with missing payloads")
1201+
wg.Wait()
1202+
1203+
t.Log("Waiting for all blocks to arrive.")
1204+
waitUntilTrueOrTimeout(t, func() bool {
1205+
t.Log("Trying to see all peers get all blocks")
1206+
height, err := peer.commit.LedgerHeight()
1207+
if height != uint64(msgCount+1) || err != nil {
1208+
return false
12311209
}
1232-
}
1210+
t.Log("All peers have same ledger height!!!")
1211+
return true
1212+
}, 60*time.Second)
12331213
}
12341214

12351215
// coordinatorMock mocking structure to capture mock interface for

0 commit comments

Comments
 (0)