Skip to content

Commit 5c8ff26

Browse files
committed
[tests] Add NetworkThread assertions
Check that P2PConnections aren't created after the NetworkThread has started and that at any time only one NetworkThread is running.
1 parent 34e08b3 commit 5c8ff26

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

test/functional/test_framework/mininode.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class P2PConnection(asyncore.dispatcher):
6969
sub-classed and the on_message() callback overridden."""
7070

7171
def __init__(self):
72+
# All P2PConnections must be created before starting the NetworkThread.
73+
# assert that the network thread is not running.
74+
assert not network_thread_running()
75+
7276
super().__init__(map=mininode_socket_map)
7377

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

419423
def network_thread_start():
420424
"""Start the network thread."""
425+
# Only one network thread may run at a time
426+
assert not network_thread_running()
427+
421428
NetworkThread().start()
422429

423430
def network_thread_running():

0 commit comments

Comments
 (0)