QA: fix rpc_setban.py race

pull/764/head
Jonas Schnelli 5 years ago
parent e00ecb3d7a
commit 6011c9d72d
No known key found for this signature in database
GPG Key ID: 1EB776BB03C7922D

@ -26,7 +26,7 @@ class SetBanTests(BitcoinTestFramework):
self.nodes[1].setban("127.0.0.1", "add") self.nodes[1].setban("127.0.0.1", "add")
# Node 0 should not be able to reconnect # Node 0 should not be able to reconnect
with self.nodes[1].assert_debug_log(expected_msgs=['dropped (banned)\n']): with self.nodes[1].assert_debug_log(expected_msgs=['dropped (banned)\n'],timeout=5):
self.restart_node(1, []) self.restart_node(1, [])
self.nodes[0].addnode("127.0.0.1:" + str(p2p_port(1)), "onetry") self.nodes[0].addnode("127.0.0.1:" + str(p2p_port(1)), "onetry")

@ -307,7 +307,8 @@ class TestNode():
wait_until(self.is_node_stopped, timeout=timeout) wait_until(self.is_node_stopped, timeout=timeout)
@contextlib.contextmanager @contextlib.contextmanager
def assert_debug_log(self, expected_msgs): def assert_debug_log(self, expected_msgs, timeout=2):
time_end = time.time() + timeout
debug_log = os.path.join(self.datadir, self.chain, 'debug.log') debug_log = os.path.join(self.datadir, self.chain, 'debug.log')
with open(debug_log, encoding='utf-8') as dl: with open(debug_log, encoding='utf-8') as dl:
dl.seek(0, 2) dl.seek(0, 2)
@ -315,13 +316,21 @@ class TestNode():
try: try:
yield yield
finally: finally:
with open(debug_log, encoding='utf-8') as dl: while True:
dl.seek(prev_size) found = True
log = dl.read() with open(debug_log, encoding='utf-8') as dl:
print_log = " - " + "\n - ".join(log.splitlines()) dl.seek(prev_size)
for expected_msg in expected_msgs: log = dl.read()
if re.search(re.escape(expected_msg), log, flags=re.MULTILINE) is None: print_log = " - " + "\n - ".join(log.splitlines())
self._raise_assertion_error('Expected message "{}" does not partially match log:\n\n{}\n\n'.format(expected_msg, print_log)) for expected_msg in expected_msgs:
if re.search(re.escape(expected_msg), log, flags=re.MULTILINE) is None:
found = False
if found:
return
if time.time() >= time_end:
break
time.sleep(0.05)
self._raise_assertion_error('Expected messages "{}" does not partially match log:\n\n{}\n\n'.format(str(expected_msgs), print_log))
@contextlib.contextmanager @contextlib.contextmanager
def assert_memory_usage_stable(self, *, increase_allowed=0.03): def assert_memory_usage_stable(self, *, increase_allowed=0.03):

Loading…
Cancel
Save