aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/peer_error_handler_test.go
blob: 790a7443b8bae7e4db0a2e21d16181571f71723d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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")
    }
}