Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show First 20 Lines • Show All 484 Lines • ▼ Show 20 Lines | def sync_with_ping(self, timeout=60): | ||||
if not self.last_message.get("pong"): | if not self.last_message.get("pong"): | ||||
return False | return False | ||||
return self.last_message["pong"].nonce == self.ping_counter | return self.last_message["pong"].nonce == self.ping_counter | ||||
wait_until(test_function, timeout=timeout, lock=mininode_lock) | wait_until(test_function, timeout=timeout, lock=mininode_lock) | ||||
self.ping_counter += 1 | self.ping_counter += 1 | ||||
# Keep our own socket map for asyncore, so that we can track disconnects | # Keep our own socket map for asyncore, so that we can track disconnects | ||||
# ourselves (to workaround an issue with closing an asyncore socket when | # ourselves (to work around an issue with closing an asyncore socket when | ||||
jasonbcox: add this one to the linter too | |||||
FabienUnsubmitted Not Done Inline ActionsYou don't want to add this one to the linter, because all 3 words (work, around and workaround) are valid. I will look at another spell check, maybe in addition to this one, because there are a lot of leftovers and this cause a lot of maintenance. Fabien: You don't want to add this one to the linter, because all 3 words (`work`, `around` and… | |||||
# using select) | # using select) | ||||
mininode_socket_map = dict() | mininode_socket_map = dict() | ||||
# 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, | ||||
# and whenever adding anything to the send buffer (in send_message()). This | # and whenever adding anything to the send buffer (in send_message()). This | ||||
# lock should be acquired in the thread running the test logic to synchronize | # 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.RLock() | ||||
class NetworkThread(threading.Thread): | class NetworkThread(threading.Thread): | ||||
def __init__(self): | def __init__(self): | ||||
super().__init__(name="NetworkThread") | super().__init__(name="NetworkThread") | ||||
def run(self): | def run(self): | ||||
while mininode_socket_map: | while mininode_socket_map: | ||||
# We check for whether to disconnect outside of the asyncore | # We check for whether to disconnect outside of the asyncore | ||||
# loop to workaround the behavior of asyncore when using | # loop to work around the behavior of asyncore when using | ||||
# select | # select | ||||
disconnected = [] | disconnected = [] | ||||
for fd, obj in mininode_socket_map.items(): | for fd, obj in mininode_socket_map.items(): | ||||
if obj.disconnect: | if obj.disconnect: | ||||
disconnected.append(obj) | disconnected.append(obj) | ||||
[obj.handle_close() for obj in disconnected] | [obj.handle_close() for obj in disconnected] | ||||
asyncore.loop(0.1, use_poll=True, map=mininode_socket_map, count=1) | asyncore.loop(0.1, use_poll=True, map=mininode_socket_map, count=1) | ||||
logger.debug("Network thread closing") | logger.debug("Network thread closing") | ||||
▲ Show 20 Lines • Show All 175 Lines • Show Last 20 Lines |
add this one to the linter too