|
@ -4,7 +4,6 @@ import ( |
|
|
"bytes" |
|
|
"bytes" |
|
|
"errors" |
|
|
"errors" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"io" |
|
|
|
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"net" |
|
|
"net" |
|
|
"net/http" |
|
|
"net/http" |
|
@ -603,9 +602,8 @@ func TestSwitchAcceptRoutine(t *testing.T) { |
|
|
err = sw.Start() |
|
|
err = sw.Start() |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
|
t.Cleanup(func() { |
|
|
t.Cleanup(func() { |
|
|
if err := sw.Stop(); err != nil { |
|
|
|
|
|
t.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
err := sw.Stop() |
|
|
|
|
|
require.NoError(t, err) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// 0. check there are no peers
|
|
|
// 0. check there are no peers
|
|
@ -630,7 +628,7 @@ func TestSwitchAcceptRoutine(t *testing.T) { |
|
|
} |
|
|
} |
|
|
}(c) |
|
|
}(c) |
|
|
} |
|
|
} |
|
|
time.Sleep(10 * time.Millisecond) |
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond) |
|
|
assert.Equal(t, cfg.MaxNumInboundPeers, sw.Peers().Size()) |
|
|
assert.Equal(t, cfg.MaxNumInboundPeers, sw.Peers().Size()) |
|
|
|
|
|
|
|
|
// 2. check we close new connections if we already have MaxNumInboundPeers peers
|
|
|
// 2. check we close new connections if we already have MaxNumInboundPeers peers
|
|
@ -640,10 +638,9 @@ func TestSwitchAcceptRoutine(t *testing.T) { |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
|
// check conn is closed
|
|
|
// check conn is closed
|
|
|
one := make([]byte, 1) |
|
|
one := make([]byte, 1) |
|
|
err = conn.SetReadDeadline(time.Now().Add(10 * time.Millisecond)) |
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
_ = conn.SetReadDeadline(time.Now().Add(10 * time.Millisecond)) |
|
|
_, err = conn.Read(one) |
|
|
_, err = conn.Read(one) |
|
|
assert.Equal(t, io.EOF, err) |
|
|
|
|
|
|
|
|
assert.Error(t, err) |
|
|
assert.Equal(t, cfg.MaxNumInboundPeers, sw.Peers().Size()) |
|
|
assert.Equal(t, cfg.MaxNumInboundPeers, sw.Peers().Size()) |
|
|
peer.Stop() |
|
|
peer.Stop() |
|
|
|
|
|
|
|
|