Fix persistent peer switch test

This commit is contained in:
Alexander Simmerl 2018-05-23 00:24:40 +02:00
parent 91b6d3f18c
commit 4848e88737
No known key found for this signature in database
GPG Key ID: 4694E95C9CC61BDA
2 changed files with 18 additions and 7 deletions

View File

@ -112,11 +112,12 @@ func createOutboundPeerAndPerformHandshake(addr *NetAddress, config *PeerConfig)
}
type remotePeer struct {
PrivKey crypto.PrivKey
Config *PeerConfig
addr *NetAddress
quit chan struct{}
channels cmn.HexBytes
PrivKey crypto.PrivKey
Config *PeerConfig
addr *NetAddress
quit chan struct{}
channels cmn.HexBytes
listenAddr string
}
func (rp *remotePeer) Addr() *NetAddress {
@ -128,7 +129,11 @@ func (rp *remotePeer) ID() ID {
}
func (rp *remotePeer) Start() {
l, e := net.Listen("tcp", "127.0.0.1:0") // any available address
if rp.listenAddr == "" {
rp.listenAddr = "127.0.0.1:0"
}
l, e := net.Listen("tcp", rp.listenAddr) // any available address
if e != nil {
golog.Fatalf("net.Listen tcp :0: %+v", e)
}

View File

@ -317,7 +317,13 @@ func TestSwitchReconnectsToPersistentPeer(t *testing.T) {
assert.False(peer.IsRunning())
// simulate another remote peer
rp = &remotePeer{PrivKey: crypto.GenPrivKeyEd25519(), Config: DefaultPeerConfig()}
rp = &remotePeer{
PrivKey: crypto.GenPrivKeyEd25519(),
Config: DefaultPeerConfig(),
// Use different interface to prevent duplicate IP filter, this will break
// beyond two peers.
listenAddr: "0.0.0.0:0",
}
rp.Start()
defer rp.Stop()