Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show First 20 Lines • Show All 578 Lines • ▼ Show 20 Lines | def sync_with_ping(self, timeout=60): | ||||
self.ping_counter += 1 | self.ping_counter += 1 | ||||
# One lock for synchronizing all data access between the networking thread (see | # One lock for synchronizing all data access between the networking thread (see | ||||
# NetworkThread below) and the thread running the test logic. For simplicity, | # NetworkThread below) and the thread running the test logic. For simplicity, | ||||
# P2PConnection acquires this lock whenever delivering a message to a P2PInterface. | # P2PConnection acquires this lock whenever delivering a message to a P2PInterface. | ||||
# This lock should be acquired in the thread running the test logic to synchronize | # This lock should be acquired in the thread running the test logic to synchronize | ||||
# access to any data shared with the P2PInterface or P2PConnection. | # access to any data shared with the P2PInterface or P2PConnection. | ||||
mininode_lock = threading.RLock() | mininode_lock = threading.Lock() | ||||
class NetworkThread(threading.Thread): | class NetworkThread(threading.Thread): | ||||
network_event_loop = None | network_event_loop = None | ||||
def __init__(self): | def __init__(self): | ||||
super().__init__(name="NetworkThread") | super().__init__(name="NetworkThread") | ||||
# There is only one event loop and no more than one thread must be | # There is only one event loop and no more than one thread must be | ||||
▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | def get_invs(self): | ||||
with mininode_lock: | with mininode_lock: | ||||
return list(self.tx_invs_received.keys()) | return list(self.tx_invs_received.keys()) | ||||
def wait_for_broadcast(self, txns, timeout=60): | def wait_for_broadcast(self, txns, timeout=60): | ||||
"""Waits for the txns (list of txids) to complete initial broadcast. | """Waits for the txns (list of txids) to complete initial broadcast. | ||||
The mempool should mark unbroadcast=False for these transactions. | The mempool should mark unbroadcast=False for these transactions. | ||||
""" | """ | ||||
# Wait until invs have been received (and getdatas sent) for each txid. | # Wait until invs have been received (and getdatas sent) for each txid. | ||||
self.wait_until(lambda: set(self.get_invs()) == set( | self.wait_until(lambda: set(self.tx_invs_received.keys()) == set( | ||||
[int(tx, 16) for tx in txns]), timeout) | [int(tx, 16) for tx in txns]), timeout) | ||||
# Flush messages and wait for the getdatas to be processed | # Flush messages and wait for the getdatas to be processed | ||||
self.sync_with_ping() | self.sync_with_ping() |