Browse Source

prep for merge

pull/1095/head
zbo14 7 years ago
committed by Anton Kaliaev
parent
commit
f97ead4f5f
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 6 additions and 28 deletions
  1. +1
    -0
      p2p/conn/connection.go
  2. +5
    -28
      p2p/switch_test.go

+ 1
- 0
p2p/conn/connection.go View File

@ -466,6 +466,7 @@ FOR_LOOP:
} }
case packetTypePong: case packetTypePong:
c.Logger.Debug("Receive Pong") c.Logger.Debug("Receive Pong")
// Should we unset pongTimer if we get other packet?
c.pongTimer.Unset() c.pongTimer.Unset()
case packetTypeMsg: case packetTypeMsg:
pkt, n, err := msgPacket{}, int(0), error(nil) pkt, n, err := msgPacket{}, int(0), error(nil)


+ 5
- 28
p2p/switch_test.go View File

@ -128,12 +128,10 @@ func TestSwitches(t *testing.T) {
ch0Msg := "channel zero" ch0Msg := "channel zero"
ch1Msg := "channel foo" ch1Msg := "channel foo"
ch2Msg := "channel bar" ch2Msg := "channel bar"
ch3Msg := "channel baz"
s1.Broadcast(byte(0x00), ch0Msg) s1.Broadcast(byte(0x00), ch0Msg)
s1.Broadcast(byte(0x01), ch1Msg) s1.Broadcast(byte(0x01), ch1Msg)
s1.Broadcast(byte(0x02), ch2Msg) 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, 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, ch1Msg, byte(0x01), s2.Reactor("foo").(*TestReactor), 10*time.Millisecond, 5*time.Second)
@ -326,33 +324,12 @@ func BenchmarkSwitches(b *testing.B) {
numSuccess, numFailure := 0, 0 numSuccess, numFailure := 0, 0
// Send random message from foo channel to another with Broadcast
// Send random message from foo channel to another
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
chID := byte(i % 4) chID := byte(i % 4)
resultChan := s1.Broadcast(chID, "test data")
for res := range resultChan {
if !s1.peers.Has(res.PeerKey) {
b.Errorf("unexpected peerKey: %s", res.PeerKey)
}
if res.Success {
numSuccess++
} else {
numFailure++
}
}
}
b.Logf("Broadcast: success: %v, failure: %v", numSuccess, numFailure)
// Send random message from foo channel to another with TryBroadcast
for i := 0; i < b.N; i++ {
chID := byte(i % 4)
resultChan := s1.TryBroadcast(chID, "test data")
for res := range resultChan {
if !s1.peers.Has(res.PeerKey) {
b.Errorf("unexpected peerKey: %s", res.PeerKey)
}
if res.Success {
successChan := s1.Broadcast(chID, "test data")
for s := range successChan {
if s {
numSuccess++ numSuccess++
} else { } else {
numFailure++ numFailure++
@ -360,7 +337,7 @@ func BenchmarkSwitches(b *testing.B) {
} }
} }
b.Logf("TryBroadcast: success: %v, failure: %v", numSuccess, numFailure)
b.Logf("success: %v, failure: %v", numSuccess, numFailure)
// Allow everything to flush before stopping switches & closing connections. // Allow everything to flush before stopping switches & closing connections.
b.StopTimer() b.StopTimer()


Loading…
Cancel
Save