aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/peer_error_handler_test.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-10-23 23:57:54 +0800
committerzelig <viktor.tron@gmail.com>2014-10-23 23:57:54 +0800
commit771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb (patch)
tree15a966dbe15e2f8388f69b396e613c7759b06f6d /p2p/peer_error_handler_test.go
parent119c5b40a7ed1aea1c871c0cb56956b8ef9303d9 (diff)
downloadgo-tangerine-771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb.tar
go-tangerine-771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb.tar.gz
go-tangerine-771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb.tar.bz2
go-tangerine-771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb.tar.lz
go-tangerine-771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb.tar.xz
go-tangerine-771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb.tar.zst
go-tangerine-771fbcc02e6d10cdf4cda2e8ec8ea23f11066feb.zip
initial commit of p2p package
Diffstat (limited to 'p2p/peer_error_handler_test.go')
-rw-r--r--p2p/peer_error_handler_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/p2p/peer_error_handler_test.go b/p2p/peer_error_handler_test.go
new file mode 100644
index 000000000..790a7443b
--- /dev/null
+++ b/p2p/peer_error_handler_test.go
@@ -0,0 +1,34 @@
+package p2p
+
+import (
+ // "fmt"
+ "net"
+ "testing"
+ "time"
+)
+
+func TestPeerErrorHandler(t *testing.T) {
+ address := &net.TCPAddr{IP: net.IP([]byte{1, 2, 3, 4}), Port: 30303}
+ peerDisconnect := make(chan DisconnectRequest)
+ peerErrorChan := NewPeerErrorChannel()
+ peh := NewPeerErrorHandler(address, peerDisconnect, peerErrorChan, NewBlacklist())
+ peh.Start()
+ defer peh.Stop()
+ for i := 0; i < 11; i++ {
+ select {
+ case <-peerDisconnect:
+ t.Errorf("expected no disconnect request")
+ default:
+ }
+ peerErrorChan <- NewPeerError(MiscError, "")
+ }
+ time.Sleep(1 * time.Millisecond)
+ select {
+ case request := <-peerDisconnect:
+ if request.addr.String() != address.String() {
+ t.Errorf("incorrect address %v != %v", request.addr, address)
+ }
+ default:
+ t.Errorf("expected disconnect request")
+ }
+}