Browse Source

Fix persistent peer switch test

pull/1520/head
Alexander Simmerl 7 years ago
parent
commit
4848e88737
No known key found for this signature in database GPG Key ID: 4694E95C9CC61BDA
2 changed files with 18 additions and 7 deletions
  1. +11
    -6
      p2p/peer_test.go
  2. +7
    -1
      p2p/switch_test.go

+ 11
- 6
p2p/peer_test.go 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)
}


+ 7
- 1
p2p/switch_test.go 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()


Loading…
Cancel
Save