tests/test_lightningd.py: fail on crash.log.

We simply kill lightningd; we should stop it properly and have a timeout
to kill it if that fails.  However, that's beyond my python skills :(

So we just look for crash.log.  Unfortunately, we usually kill
lightningd before it's finished writing it.  So we look for it and
don't kill lightningd, just wait in this case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-09-12 14:25:54 +09:30 committed by Christian Decker
parent ef28b6112c
commit 64a26b06e7
2 changed files with 27 additions and 1 deletions

View File

@ -151,19 +151,42 @@ class BaseLightningDTests(unittest.TestCase):
print("-"*80)
return 1 if errors else 0
def getCrashLog(self, node):
try:
crashlog = os.path.join(node.daemon.lightning_dir, 'crash.log')
with open(crashlog, 'r') as f:
return f.readlines(), crashlog
except:
return None, None
def printCrashLog(self, node):
errors, fname = self.getCrashLog(node)
if errors:
print("-"*10, "{} (last 50 lines)".format(fname), "-"*10)
for l in errors[-50:]:
print(l, end='')
print("-"*80)
return 1 if errors else 0
def tearDown(self):
self.node_factory.killall()
self.executor.shutdown(wait=False)
err_count = 0
# Do not check for valgrind error files if it is disabled
if VALGRIND:
err_count = 0
for node in self.node_factory.nodes:
err_count += self.printValgrindErrors(node)
if err_count:
raise ValueError(
"{} nodes reported valgrind errors".format(err_count))
for node in self.node_factory.nodes:
err_count += self.printCrashLog(node)
if err_count:
raise ValueError(
"{} nodes had crash.log files".format(err_count))
class LightningDTests(BaseLightningDTests):
def connect(self):
l1 = self.node_factory.get_node()

View File

@ -231,6 +231,9 @@ class LightningD(TailableProc):
logging.info("LightningD started")
def stop(self):
# If it's already crashing, wait a bit for log dump.
if os.path.isfile(os.path.join(self.lightning_dir, 'crash.log')):
time.sleep(2)
TailableProc.stop(self)
logging.info("LightningD stopped")