Skip to content

Commit

Permalink
test: add node.chain_path and node.debug_log_path
Browse files Browse the repository at this point in the history
To allow easier access to the node's datadir and debug logs.
  • Loading branch information
jamesob committed Oct 20, 2021
1 parent 02ccf10 commit 23f8561
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import collections
import shlex
import sys
from pathlib import Path

from .authproxy import JSONRPCException
from .descriptors import descsum_create
Expand Down Expand Up @@ -368,21 +369,28 @@ def is_node_stopped(self):
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
wait_until_helper(self.is_node_stopped, timeout=timeout, timeout_factor=self.timeout_factor)

@property
def chain_path(self) -> Path:
return Path(self.datadir) / self.chain

@property
def debug_log_path(self) -> Path:
return self.chain_path / 'debug.log'

@contextlib.contextmanager
def assert_debug_log(self, expected_msgs, unexpected_msgs=None, timeout=2):
if unexpected_msgs is None:
unexpected_msgs = []
time_end = time.time() + timeout * self.timeout_factor
debug_log = os.path.join(self.datadir, self.chain, 'debug.log')
with open(debug_log, encoding='utf-8') as dl:
with open(self.debug_log_path, encoding='utf-8') as dl:
dl.seek(0, 2)
prev_size = dl.tell()

yield

while True:
found = True
with open(debug_log, encoding='utf-8') as dl:
with open(self.debug_log_path, encoding='utf-8') as dl:
dl.seek(prev_size)
log = dl.read()
print_log = " - " + "\n - ".join(log.splitlines())
Expand Down

0 comments on commit 23f8561

Please sign in to comment.