Skip to content

Commit

Permalink
[tests] Add NetworkThread assertions
Browse files Browse the repository at this point in the history
Check that P2PConnections aren't created after the NetworkThread
has started and that at any time only one NetworkThread is running.
  • Loading branch information
jnewbery committed Dec 11, 2017
1 parent 34e08b3 commit 5c8ff26
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/functional/test_framework/mininode.py
Expand Up @@ -69,6 +69,10 @@ class P2PConnection(asyncore.dispatcher):
sub-classed and the on_message() callback overridden."""

def __init__(self):
# All P2PConnections must be created before starting the NetworkThread.
# assert that the network thread is not running.
assert not network_thread_running()

super().__init__(map=mininode_socket_map)

def peer_connect(self, dstaddr, dstport, net="regtest"):
Expand Down Expand Up @@ -418,6 +422,9 @@ def run(self):

def network_thread_start():
"""Start the network thread."""
# Only one network thread may run at a time
assert not network_thread_running()

NetworkThread().start()

def network_thread_running():
Expand Down

0 comments on commit 5c8ff26

Please sign in to comment.