Skip to content

Commit

Permalink
[test] wait for disconnect_p2ps to be reflected in getpeerinfo
Browse files Browse the repository at this point in the history
-Waiting is important to avoid race conditions,
especially if testing peer info through rpc later.
-Wait for mininodes to be disconnected only, even
though it's more complex, because we may still want
to be connected to test nodes.
  • Loading branch information
glozow committed Jun 16, 2020
1 parent e81942d commit aeb9fb4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from .authproxy import JSONRPCException
from .descriptors import descsum_create
from .messages import MY_SUBVERSION
from .util import (
MAX_NODES,
append_config,
Expand Down Expand Up @@ -549,11 +550,16 @@ def p2p(self):
assert self.p2ps, self._node_msg("No p2p connection")
return self.p2ps[0]

def num_connected_mininodes(self):
"""Return number of test framework p2p connections to the node."""
return len([peer for peer in self.getpeerinfo() if peer['subver'] == MY_SUBVERSION])

def disconnect_p2ps(self):
"""Close all p2p connections to the node."""
for p in self.p2ps:
p.peer_disconnect()
del self.p2ps[:]
wait_until(lambda: self.num_connected_mininodes() == 0)


class TestNodeCLIAttr:
Expand Down

0 comments on commit aeb9fb4

Please sign in to comment.