Skip to content

Commit

Permalink
Add race-condition debugging tool to mininode
Browse files Browse the repository at this point in the history
  • Loading branch information
sdaftuar committed Jan 7, 2016
1 parent 605c178 commit 82a0ce0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions qa/rpc-tests/test_framework/mininode.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,18 @@ def __repr__(self):
class NodeConnCB(object):
def __init__(self):
self.verack_received = False
# deliver_sleep_time is helpful for debugging race conditions in p2p
# tests; it causes message delivery to sleep for the specified time
# before acquiring the global lock and delivering the next message.
self.deliver_sleep_time = None

def set_deliver_sleep_time(self, value):
with mininode_lock:
self.deliver_sleep_time = value

def get_deliver_sleep_time(self):
with mininode_lock:
return self.deliver_sleep_time

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

def deliver(self, conn, message):
deliver_sleep = self.get_deliver_sleep_time()
if deliver_sleep is not None:
time.sleep(deliver_sleep)
with mininode_lock:
try:
getattr(self, 'on_' + message.command)(conn, message)
Expand Down

0 comments on commit 82a0ce0

Please sign in to comment.