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 | ||||
nakihito: This `workaround` is not being used as a noun. Rather, it is being used to describe the method… | |||||
# 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 workaround the behavior of asyncore when using | ||||
FabienUnsubmitted Not Done Inline ActionsThis one is still missing Fabien: This one is still missing | |||||
# 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 |
This workaround is not being used as a noun. Rather, it is being used to describe the method by which something is being done and as such should be split into two different words.