Skip to content

Commit 82a0ce0

Browse files
committed
Add race-condition debugging tool to mininode
1 parent 605c178 commit 82a0ce0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

qa/rpc-tests/test_framework/mininode.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,18 @@ def __repr__(self):
10041004
class NodeConnCB(object):
10051005
def __init__(self):
10061006
self.verack_received = False
1007+
# deliver_sleep_time is helpful for debugging race conditions in p2p
1008+
# tests; it causes message delivery to sleep for the specified time
1009+
# before acquiring the global lock and delivering the next message.
1010+
self.deliver_sleep_time = None
1011+
1012+
def set_deliver_sleep_time(self, value):
1013+
with mininode_lock:
1014+
self.deliver_sleep_time = value
1015+
1016+
def get_deliver_sleep_time(self):
1017+
with mininode_lock:
1018+
return self.deliver_sleep_time
10071019

10081020
# Spin until verack message is received from the node.
10091021
# Tests may want to use this as a signal that the test can begin.
@@ -1017,6 +1029,9 @@ def wait_for_verack(self):
10171029
time.sleep(0.05)
10181030

10191031
def deliver(self, conn, message):
1032+
deliver_sleep = self.get_deliver_sleep_time()
1033+
if deliver_sleep is not None:
1034+
time.sleep(deliver_sleep)
10201035
with mininode_lock:
10211036
try:
10221037
getattr(self, 'on_' + message.command)(conn, message)

0 commit comments

Comments
 (0)