aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/peer_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'p2p/peer_test.go')
-rw-r--r--p2p/peer_test.go24
1 files changed, 7 insertions, 17 deletions
diff --git a/p2p/peer_test.go b/p2p/peer_test.go
index fb76818a0..59dcb7ba4 100644
--- a/p2p/peer_test.go
+++ b/p2p/peer_test.go
@@ -50,8 +50,6 @@ func testPeer(protos []Protocol) (func(), *conn, *Peer, <-chan DiscReason) {
}
func TestPeerProtoReadMsg(t *testing.T) {
- defer testlog(t).detach()
-
done := make(chan struct{})
proto := Protocol{
Name: "a",
@@ -88,8 +86,6 @@ func TestPeerProtoReadMsg(t *testing.T) {
}
func TestPeerProtoEncodeMsg(t *testing.T) {
- defer testlog(t).detach()
-
proto := Protocol{
Name: "a",
Length: 2,
@@ -112,8 +108,6 @@ func TestPeerProtoEncodeMsg(t *testing.T) {
}
func TestPeerWriteForBroadcast(t *testing.T) {
- defer testlog(t).detach()
-
closer, rw, peer, peerErr := testPeer([]Protocol{discard})
defer closer()
@@ -152,8 +146,6 @@ func TestPeerWriteForBroadcast(t *testing.T) {
}
func TestPeerPing(t *testing.T) {
- defer testlog(t).detach()
-
closer, rw, _, _ := testPeer(nil)
defer closer()
if err := SendItems(rw, pingMsg); err != nil {
@@ -165,26 +157,24 @@ func TestPeerPing(t *testing.T) {
}
func TestPeerDisconnect(t *testing.T) {
- defer testlog(t).detach()
-
closer, rw, _, disc := testPeer(nil)
defer closer()
if err := SendItems(rw, discMsg, DiscQuitting); err != nil {
t.Fatal(err)
}
- if err := ExpectMsg(rw, discMsg, []interface{}{DiscRequested}); err != nil {
- t.Error(err)
- }
- closer()
- if reason := <-disc; reason != DiscRequested {
- t.Errorf("run returned wrong reason: got %v, want %v", reason, DiscRequested)
+ select {
+ case reason := <-disc:
+ if reason != DiscQuitting {
+ t.Errorf("run returned wrong reason: got %v, want %v", reason, DiscRequested)
+ }
+ case <-time.After(500 * time.Millisecond):
+ t.Error("peer did not return")
}
}
// This test is supposed to verify that Peer can reliably handle
// multiple causes of disconnection occurring at the same time.
func TestPeerDisconnectRace(t *testing.T) {
- defer testlog(t).detach()
maybe := func() bool { return rand.Intn(1) == 1 }
for i := 0; i < 1000; i++ {