From fd2875f2edd40c2f8f2a786385e330c3ac7b2af7 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Tue, 23 Dec 2014 17:59:24 -0800 Subject: [PATCH] fixing race in swarm --- net/swarm/swarm_test.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/net/swarm/swarm_test.go b/net/swarm/swarm_test.go index c0a1ab9fa..3d692a064 100644 --- a/net/swarm/swarm_test.go +++ b/net/swarm/swarm_test.go @@ -248,15 +248,21 @@ func TestConnHandler(t *testing.T) { <-time.After(time.Millisecond) // should've gotten 5 by now. - close(gotconn) + + swarms[0].SetConnHandler(nil) expect := 4 - actual := 0 - for _ = range gotconn { - actual++ + for i := 0; i < expect; i++ { + select { + case <-time.After(time.Second): + t.Fatal("failed to get connections") + case <-gotconn: + } } - if actual != expect { - t.Fatal("should have connected to %d swarms. got: %d", actual, expect) + select { + case <-gotconn: + t.Fatalf("should have connected to %d swarms", expect) + default: } }