diff options
author | Felix Lange <fjl@twurst.com> | 2017-02-24 16:58:04 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2017-02-28 17:20:29 +0800 |
commit | 96ae35e2ac8c360781407d7294081aabdcbb3652 (patch) | |
tree | 378cc7aae99127a4e85a721e5cd319ced87e103a /p2p/peer_test.go | |
parent | 35e8308bf76df11c3c1e8d11fac782814583ea5c (diff) | |
download | dexon-96ae35e2ac8c360781407d7294081aabdcbb3652.tar.gz dexon-96ae35e2ac8c360781407d7294081aabdcbb3652.tar.zst dexon-96ae35e2ac8c360781407d7294081aabdcbb3652.zip |
p2p, p2p/discover, p2p/nat: rework logging using context keys
Diffstat (limited to 'p2p/peer_test.go')
-rw-r--r-- | p2p/peer_test.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/p2p/peer_test.go b/p2p/peer_test.go index f44300b15..a3e1c74fd 100644 --- a/p2p/peer_test.go +++ b/p2p/peer_test.go @@ -43,7 +43,7 @@ var discard = Protocol{ }, } -func testPeer(protos []Protocol) (func(), *conn, *Peer, <-chan DiscReason) { +func testPeer(protos []Protocol) (func(), *conn, *Peer, <-chan error) { fd1, fd2 := net.Pipe() c1 := &conn{fd: fd1, transport: newTestTransport(randomID(), fd1)} c2 := &conn{fd: fd2, transport: newTestTransport(randomID(), fd2)} @@ -53,15 +53,17 @@ func testPeer(protos []Protocol) (func(), *conn, *Peer, <-chan DiscReason) { } peer := newPeer(c1, protos) - errc := make(chan DiscReason, 1) - go func() { errc <- peer.run() }() + errc := make(chan error, 1) + go func() { + _, err := peer.run() + errc <- err + }() closer := func() { c2.close(errors.New("close func called")) } return closer, c2, peer, errc } func TestPeerProtoReadMsg(t *testing.T) { - done := make(chan struct{}) proto := Protocol{ Name: "a", Length: 5, @@ -75,7 +77,6 @@ func TestPeerProtoReadMsg(t *testing.T) { if err := ExpectMsg(rw, 4, []uint{3}); err != nil { t.Error(err) } - close(done) return nil }, } @@ -88,9 +89,10 @@ func TestPeerProtoReadMsg(t *testing.T) { Send(rw, baseProtocolLength+4, []uint{3}) select { - case <-done: case err := <-errc: - t.Errorf("peer returned: %v", err) + if err != errProtocolReturned { + t.Errorf("peer returned error: %v", err) + } case <-time.After(2 * time.Second): t.Errorf("receive timeout") } @@ -137,8 +139,8 @@ func TestPeerDisconnect(t *testing.T) { } select { case reason := <-disc: - if reason != DiscRequested { - t.Errorf("run returned wrong reason: got %v, want %v", reason, DiscRequested) + if reason != DiscQuitting { + t.Errorf("run returned wrong reason: got %v, want %v", reason, DiscQuitting) } case <-time.After(500 * time.Millisecond): t.Error("peer did not return") |