diff --git a/p2p/conn/connection.go b/p2p/conn/connection.go index c0f7efcd0..04ca4228d 100644 --- a/p2p/conn/connection.go +++ b/p2p/conn/connection.go @@ -320,7 +320,7 @@ FOR_LOOP: c.Logger.Debug("Send Ping") wire.WriteByte(packetTypePing, c.bufWriter, &n, &err) c.sendMonitor.Update(int(n)) - // c.flush + // should be c.flush go c.flush() c.Logger.Debug("Starting pong timer") c.pongTimer.Set() diff --git a/p2p/switch_test.go b/p2p/switch_test.go index 75f9640b1..9c8b763ec 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -128,14 +128,17 @@ func TestSwitches(t *testing.T) { ch0Msg := "channel zero" ch1Msg := "channel foo" ch2Msg := "channel bar" + ch3Msg := "channel baz" s1.Broadcast(byte(0x00), ch0Msg) s1.Broadcast(byte(0x01), ch1Msg) s1.Broadcast(byte(0x02), ch2Msg) + s1.TryBroadcast(byte(0x03), ch3Msg) assertMsgReceivedWithTimeout(t, ch0Msg, byte(0x00), s2.Reactor("foo").(*TestReactor), 10*time.Millisecond, 5*time.Second) assertMsgReceivedWithTimeout(t, ch1Msg, byte(0x01), s2.Reactor("foo").(*TestReactor), 10*time.Millisecond, 5*time.Second) assertMsgReceivedWithTimeout(t, ch2Msg, byte(0x02), s2.Reactor("bar").(*TestReactor), 10*time.Millisecond, 5*time.Second) + assertMsgReceivedWithTimeout(t, ch3Msg, byte(0x03), s2.Reactor("bar").(*TestReactor), 10*time.Millisecond, 5*time.Second) } func assertMsgReceivedWithTimeout(t *testing.T, msg string, channel byte, reactor *TestReactor, checkPeriod, timeout time.Duration) { @@ -328,8 +331,11 @@ func BenchmarkSwitches(b *testing.B) { for i := 0; i < b.N; i++ { chID := byte(i % 4) successChan := s1.Broadcast(chID, "test data") - for s := range successChan { - if s { + for res := range successChan { + if !s1.peers.Has(res.PeerKey) { + b.Error("Unexpected peerKey: " + res.PeerKey) + } + if res.Success { numSuccess++ } else { numFailure++