Skip to content

Commit

Permalink
Fix gossip state-transfer test
Browse files Browse the repository at this point in the history
Fixed a send on closed channel error and also
did a refactoring of that method

Change-Id: Ic09458ea1f02b54d6e7f2da987a67fe4e708007d
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Nov 16, 2016
1 parent f4dcb08 commit 90a094d
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 90a094d

Please sign in to comment.