From a2938fd35b2c5920874b9aacb1c8a3418c6cd582 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 18 Mar 2015 12:42:11 -0700 Subject: [PATCH] p2p: fix switch test for Broadcast returning success channel --- p2p/switch.go | 2 +- p2p/switch_test.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/p2p/switch.go b/p2p/switch.go index 99afe561e..36da32aa6 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -166,7 +166,7 @@ func (sw *Switch) IsDialing(addr *NetAddress) bool { // which receives success values for each attempted send (false if times out) func (sw *Switch) Broadcast(chId byte, msg interface{}) chan bool { if atomic.LoadUint32(&sw.stopped) == 1 { - return + return nil } successChan := make(chan bool, len(sw.peers.List())) log.Debug("Broadcast", "channel", chId, "msg", msg) diff --git a/p2p/switch_test.go b/p2p/switch_test.go index 80a5a5794..a260df27a 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -197,9 +197,14 @@ func BenchmarkSwitches(b *testing.B) { // Send random message from one channel to another for i := 0; i < b.N; i++ { chId := byte(i % 4) - nS, nF := s1.Broadcast(chId, "test data") - numSuccess += nS - numFailure += nF + successChan := s1.Broadcast(chId, "test data") + for s := range successChan { + if s { + numSuccess += 1 + } else { + numFailure += 1 + } + } } log.Warn(Fmt("success: %v, failure: %v", numSuccess, numFailure))