Skip to content

Commit

Permalink
lnprototest: add the print_logs to print the node logs
Browse files Browse the repository at this point in the history
During the failure of one test, we want to see what is happening and why the test is failing.

This is usualy not trivial to understand and required to consult the log. Now there is the possibility to add a flag to tell the runner to store the log and print in the lnprototest logging.

Changelog-Add: add the `print_logs` to the runner stop method to have the possibility to print the log when it is needed.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Mar 30, 2022
1 parent c413a31 commit c1ff0a1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lnprototest/clightning/clightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import shutil
import logging

from datetime import date
from concurrent import futures
from ephemeral_port_reserve import reserve
from lnprototest.backend import Bitcoind
Expand Down Expand Up @@ -169,12 +170,19 @@ def shutdown(self) -> None:
self.rpc.stop()
self.bitcoind.stop()

def stop(self) -> None:
def stop(self, print_logs: bool = False) -> None:
self.logger.debug("[STOP]")
self.shutdown()
self.running = False
for c in self.conns.values():
cast(CLightningConn, c).connection.connection.close()
if print_logs:
log_path = f"{self.lightning_dir}/log"
with open(log_path) as log:
self.logger.info("---------- c-lightning logging ----------------")
self.logger.info(log.readlines())
# now we make a backup of the log
shutil.copy(log_path, f'/tmp/log_{date.today().strftime("%b-%d-%Y")}')
shutil.rmtree(os.path.join(self.lightning_dir, "regtest"))

def restart(self) -> None:
Expand Down
9 changes: 8 additions & 1 deletion lnprototest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ def start(self) -> None:
pass

@abstractmethod
def stop(self) -> None:
def stop(self, print_log: bool = False) -> None:
"""
Stop the runner, and print all the log that the ln
implementation produced.
Print the log is useful when we have a failure e we need
to debug what happens during the tests.
"""
pass

@abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def run_runner(runner: Runner, test: Union[Sequence, List[Event], Event]) -> Non
try:
runner.run(test)
except Exception as ex:
runner.stop()
runner.stop(print_log=True)
logging.error(get_traceback(ex))
assert False, ex

Expand Down

0 comments on commit c1ff0a1

Please sign in to comment.