@cryptotaxi247 / kubo / commits / fd2875f2e

fixing race in swarm

Juan Batiz-Benet committed Dec 23, 2014 at 17:59 UTC fd2875f2edd40c2f8f2a786385e330c3ac7b2af7
1 file changed +12 -6
net/swarm/swarm_test.go
+12 -6
@@ -248,15 +248,21 @@ func TestConnHandler(t *testing.T) {
248
249 <-time.After(time.Millisecond)
250 // should've gotten 5 by now.
251 - close(gotconn)
251 +
252 + swarms[0].SetConnHandler(nil)
253
254 expect := 4
254 - actual := 0
255 - for _ = range gotconn {
256 - actual++
255 + for i := 0; i < expect; i++ {
256 + select {
257 + case <-time.After(time.Second):
258 + t.Fatal("failed to get connections")
259 + case <-gotconn:
260 + }
261 }
262
259 - if actual != expect {
260 - t.Fatal("should have connected to %d swarms. got: %d", actual, expect)
263 + select {
264 + case <-gotconn:
265 + t.Fatalf("should have connected to %d swarms", expect)
266 + default:
267 }
268 }