Skip to content

Commit 90a094d

Browse files
committed
Fix gossip state-transfer test
Fixed a send on closed channel error and also did a refactoring of that method Change-Id: Ic09458ea1f02b54d6e7f2da987a67fe4e708007d Signed-off-by: Yacov Manevich <[email protected]>
1 parent f4dcb08 commit 90a094d

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

gossip/state/state_test.go

+8-15
Original file line numberDiff line numberDiff line change
@@ -321,29 +321,22 @@ func TestNewGossipStateProvider_SendingManyMessages(t *testing.T) {
321321
}
322322

323323
func waitUntilTrueOrTimeout(t *testing.T, predicate func() bool, timeout time.Duration) {
324-
ch := make(chan interface{})
325-
defer close(ch)
326-
done := false
324+
ch := make(chan struct{})
327325
go func () {
328326
logger.Debug("[@@@@@]: Started to spin off, until predicate will be satisfied.")
329-
for !done {
330-
if !predicate() {
331-
time.Sleep(1 * time.Second)
332-
continue
333-
}
334-
ch <- struct {}{}
335-
break
327+
for !predicate() {
328+
time.Sleep(1 * time.Second)
336329
}
330+
ch <- struct {}{}
337331
logger.Debug("[@@@@@]: Done.")
338332
}()
339333

340334
select {
341-
case <-ch: { }
335+
case <-ch:
336+
break
342337
case <-time.After(timeout):
343-
{
344-
t.Fatal("Timeout has expired")
345-
}
338+
t.Fatal("Timeout has expired")
339+
break
346340
}
347-
done = true
348341
logger.Debug("[>>>>>] Stop wainting until timeout or true")
349342
}

0 commit comments

Comments
 (0)