diff options
author | Jonas Schnelli <dev@jonasschnelli.ch> | 2019-08-20 14:31:00 +0200 |
---|---|---|
committer | Jonas Schnelli <dev@jonasschnelli.ch> | 2019-08-21 14:18:40 +0200 |
commit | 6011c9d72d1df5c2cd09de6f85c21eb4f7eb1ba8 (patch) | |
tree | e56dbef9314a39a2a31c72e5767bc9538ee8f956 /test/functional/test_framework | |
parent | e00ecb3d7aaee463643e486ca03c318e192b8058 (diff) |
QA: fix rpc_setban.py race
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-x | test/functional/test_framework/test_node.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index df027397d2..9667cf4ea4 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -307,7 +307,8 @@ class TestNode(): wait_until(self.is_node_stopped, timeout=timeout) @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') with open(debug_log, encoding='utf-8') as dl: dl.seek(0, 2) @@ -315,13 +316,21 @@ class TestNode(): try: yield finally: - with open(debug_log, encoding='utf-8') as dl: - dl.seek(prev_size) - log = dl.read() - print_log = " - " + "\n - ".join(log.splitlines()) - for expected_msg in expected_msgs: - if re.search(re.escape(expected_msg), log, flags=re.MULTILINE) is None: - self._raise_assertion_error('Expected message "{}" does not partially match log:\n\n{}\n\n'.format(expected_msg, print_log)) + while True: + found = True + with open(debug_log, encoding='utf-8') as dl: + dl.seek(prev_size) + log = dl.read() + print_log = " - " + "\n - ".join(log.splitlines()) + 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 def assert_memory_usage_stable(self, *, increase_allowed=0.03): |