From 9021bb26d1ed587c96fe2256b26b8c9f21c64745 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 6 Oct 2020 11:57:51 +0200 Subject: [PATCH] pyln: Decode process output once before storing it --- contrib/pyln-testing/pyln/testing/utils.py | 14 +++++++++++--- tests/test_connection.py | 4 ++-- tests/test_gossip.py | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index 6a965f128..ca3121b02 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -20,6 +20,7 @@ import sqlite3 import string import struct import subprocess +import sys import threading import time import warnings @@ -202,15 +203,22 @@ class TailableProc(object): for line in iter(self.proc.stdout.readline, ''): if len(line) == 0: break - if self.log_filter(line.decode('ASCII')): + + line = line.decode('ASCII').rstrip() + + if self.log_filter(line): continue + if self.verbose: - logging.debug("%s: %s", self.prefix, line.decode().rstrip()) + sys.stdout.write("{}: {}\n".format(self.prefix, line)) + with self.logs_cond: - self.logs.append(str(line.rstrip())) + self.logs.append(line) self.logs_cond.notifyAll() + self.running = False self.proc.stdout.close() + if self.proc.stderr: for line in iter(self.proc.stderr.readline, ''): if len(line) == 0: diff --git a/tests/test_connection.py b/tests/test_connection.py index f2d2bd4e8..6a96b90ad 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -2125,7 +2125,7 @@ def test_dataloss_protection(node_factory, bitcoind): # be zero) "[0-9a-f]{64}" # my_current_per_commitment_point - "0[23][0-9a-f]{64}'$") + "0[23][0-9a-f]{64}") # After an htlc, we should get different results (two more commits) l1.pay(l2, 200000000) @@ -2148,7 +2148,7 @@ def test_dataloss_protection(node_factory, bitcoind): # your_last_per_commitment_secret "[0-9a-f]{64}" # my_current_per_commitment_point - "0[23][0-9a-f]{64}'$") + "0[23][0-9a-f]{64}") # Now, move l2 back in time. l2.stop() diff --git a/tests/test_gossip.py b/tests/test_gossip.py index 92f9d8b31..c3f8cbd0c 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -354,7 +354,7 @@ def test_gossip_weirdalias(node_factory, bitcoind): {'alias': normal_name} ] l1, l2 = node_factory.get_nodes(2, opts=opts) - weird_name_json = json.encoder.JSONEncoder().encode(weird_name)[1:-1].replace('\\', '\\\\') + weird_name_json = json.encoder.JSONEncoder().encode(weird_name)[1:-1] aliasline = l1.daemon.is_in_log('Server started with public key .* alias') assert weird_name_json in str(aliasline) assert l2.daemon.is_in_log('Server started with public key .* alias {}'