Browse Source

p2p: fix network update test (#6361)

pull/6379/head
Sam Kleinman 4 years ago
committed by GitHub
parent
commit
fce665ef06
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions
  1. +14
    -0
      p2p/p2ptest/network.go
  2. +1
    -0
      p2p/p2ptest/require.go
  3. +1
    -1
      p2p/router_test.go

+ 14
- 0
p2p/p2ptest/network.go View File

@ -294,11 +294,25 @@ func (n *Node) MakeChannelNoCleanup(
// MakePeerUpdates opens a peer update subscription, with automatic cleanup.
// It checks that all updates have been consumed during cleanup.
func (n *Node) MakePeerUpdates(t *testing.T) *p2p.PeerUpdates {
t.Helper()
sub := n.PeerManager.Subscribe()
t.Cleanup(func() {
t.Helper()
RequireNoUpdates(t, sub)
sub.Close()
})
return sub
}
// MakePeerUpdatesNoRequireEmpty opens a peer update subscription, with automatic cleanup.
// It does *not* check that all updates have been consumed, but will
// close the update channel.
func (n *Node) MakePeerUpdatesNoRequireEmpty(t *testing.T) *p2p.PeerUpdates {
sub := n.PeerManager.Subscribe()
t.Cleanup(func() {
sub.Close()
})
return sub
}

+ 1
- 0
p2p/p2ptest/require.go View File

@ -93,6 +93,7 @@ func RequireSendReceive(
// RequireNoUpdates requires that a PeerUpdates subscription is empty.
func RequireNoUpdates(t *testing.T, peerUpdates *p2p.PeerUpdates) {
t.Helper()
select {
case update := <-peerUpdates.Updates():
require.Fail(t, "unexpected peer updates", "got %v", update)


+ 1
- 1
p2p/router_test.go View File

@ -80,7 +80,7 @@ func TestRouter_Network(t *testing.T) {
// We then submit an error for a peer, and watch it get disconnected and
// then reconnected as the router retries it.
peerUpdates := local.MakePeerUpdates(t)
peerUpdates := local.MakePeerUpdatesNoRequireEmpty(t)
channel.Error <- p2p.PeerError{
NodeID: peers[0].NodeID,
Err: errors.New("boom"),


Loading…
Cancel
Save