From 90a094d1f0b0f95a8d932690b54583fce22f543d Mon Sep 17 00:00:00 2001 From: YACOVM Date: Wed, 16 Nov 2016 10:37:20 +0200 Subject: [PATCH] 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 --- gossip/state/state_test.go | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/gossip/state/state_test.go b/gossip/state/state_test.go index d778b181ede..fbf756a1a2b 100644 --- a/gossip/state/state_test.go +++ b/gossip/state/state_test.go @@ -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") }