@@ -1171,65 +1171,45 @@ func TestNewGossipStateProvider_BatchingOfStateRequest(t *testing.T) {
1171
1171
}
1172
1172
_ , peerCh := peer .g .Accept (naiveStateMsgPredicate , true )
1173
1173
1174
- messageCh := make ( chan struct {})
1175
- stopWaiting := make ( chan struct {} )
1174
+ wg := sync. WaitGroup {}
1175
+ wg . Add ( expectedMessagesCnt )
1176
1176
1177
1177
// Number of submitted messages is defAntiEntropyBatchSize + 5, therefore
1178
1178
// expected number of batches is expectedMessagesCnt = 2. Following go routine
1179
1179
// makes sure it receives expected amount of messages and sends signal of success
1180
1180
// 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 ()
1195
1185
}
1186
+ }()
1196
1187
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 )
1199
1198
1200
1199
// Waits for message which indicates that expected number of message batches received
1201
1200
// 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
1231
1209
}
1232
- }
1210
+ t .Log ("All peers have same ledger height!!!" )
1211
+ return true
1212
+ }, 60 * time .Second )
1233
1213
}
1234
1214
1235
1215
// coordinatorMock mocking structure to capture mock interface for
0 commit comments