Browse Source

switch test modification

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

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

@ -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()


+ 8
- 2
p2p/switch_test.go View File

@ -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++


Loading…
Cancel
Save