Skip to content

Commit

Permalink
Merge "Fix gossip state-transfer test"
Browse files Browse the repository at this point in the history
  • Loading branch information
Srinivasan Muralidharan authored and Gerrit Code Review committed Nov 16, 2016
2 parents 742443e + 90a094d commit b2390c1
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions gossip/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,29 +321,22 @@ func TestNewGossipStateProvider_SendingManyMessages(t *testing.T) {
}

func waitUntilTrueOrTimeout(t *testing.T, predicate func() bool, timeout time.Duration) {
ch := make(chan interface{})
defer close(ch)
done := false
ch := make(chan struct{})
go func () {
logger.Debug("[@@@@@]: Started to spin off, until predicate will be satisfied.")
for !done {
if !predicate() {
time.Sleep(1 * time.Second)
continue
}
ch <- struct {}{}
break
for !predicate() {
time.Sleep(1 * time.Second)
}
ch <- struct {}{}
logger.Debug("[@@@@@]: Done.")
}()

select {
case <-ch: { }
case <-ch:
break
case <-time.After(timeout):
{
t.Fatal("Timeout has expired")
}
t.Fatal("Timeout has expired")
break
}
done = true
logger.Debug("[>>>>>] Stop wainting until timeout or true")
}

0 comments on commit b2390c1

Please sign in to comment.