From 0cf3e19e0bb4e7989cea797378e20b24bb207e86 Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Sat, 7 Mar 2020 18:05:57 -0600 Subject: [PATCH] pyln-testing: save stderr logs for checking just for convenience's sake --- contrib/pyln-testing/pyln/testing/utils.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index a452d1f6b..62087ecf3 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -140,6 +140,7 @@ class TailableProc(object): self.proc = None self.outputDir = outputDir self.logsearch_start = 0 + self.err_logs = [] # Should we be logging lines we read from stdout? self.verbose = verbose @@ -210,6 +211,10 @@ class TailableProc(object): self.running = False self.proc.stdout.close() if self.proc.stderr: + for line in iter(self.proc.stderr.readline, ''): + if len(line) == 0: + break + self.err_logs.append(line.rstrip().decode('ASCII')) self.proc.stderr.close() def is_in_log(self, regex, start=0): @@ -224,6 +229,18 @@ class TailableProc(object): logging.debug("Did not find '%s' in logs", regex) return None + def is_in_stderr(self, regex): + """Look for `regex` in stderr.""" + + ex = re.compile(regex) + for l in self.err_logs: + if ex.search(l): + logging.debug("Found '%s' in stderr", regex) + return l + + logging.debug("Did not find '%s' in stderr", regex) + return None + def wait_for_logs(self, regexs, timeout=TIMEOUT): """Look for `regexs` in the logs. @@ -637,8 +654,8 @@ class LightningNode(object): info = self.rpc.getinfo() return 'warning_bitcoind_sync' not in info and 'warning_lightningd_sync' not in info - def start(self, wait_for_bitcoind_sync=True): - self.daemon.start() + def start(self, wait_for_bitcoind_sync=True, stderr=None): + self.daemon.start(stderr=stderr) # Cache `getinfo`, we'll be using it a lot self.info = self.rpc.getinfo() # This shortcut is sufficient for our simple tests.