backup: Fix flaky test due to logs being dropped on shutdown

We were writing logs directly before killing `lightningd` which resulted in
the logs being lost. The subsequent check for the log-lines then would fail
obviously.
This commit is contained in:
Christian Decker
2020-05-15 17:05:03 +02:00
parent 162b5cc977
commit 9b5a9076d4
2 changed files with 10 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ import os
import struct import struct
import sys import sys
import sqlite3 import sqlite3
import time
plugin = Plugin() plugin = Plugin()
@@ -252,6 +253,7 @@ def get_backend(destination, create=False, require_init=False):
def abort(reason: str) -> None: def abort(reason: str) -> None:
plugin.log(reason) plugin.log(reason)
time.sleep(1)
plugin.rpc.stop() plugin.rpc.stop()
raise ValueError() raise ValueError()

View File

@@ -177,16 +177,24 @@ def test_failing_restore(nf, directory):
'plugin': plugin_path, 'plugin': plugin_path,
'backup-destination': bdest, 'backup-destination': bdest,
} }
def section(comment):
print("="*25, comment, "="*25)
section("Starting node for the first time")
l1 = nf.get_node(options=opts, cleandir=False) l1 = nf.get_node(options=opts, cleandir=False)
l1.stop() l1.stop()
# Now fudge the data_version: # Now fudge the data_version:
section("Simulating a restore of an old version")
l1.db.execute("UPDATE vars SET intval = intval - 2 WHERE name = 'data_version'") l1.db.execute("UPDATE vars SET intval = intval - 2 WHERE name = 'data_version'")
section("Restarting node, should fail")
with pytest.raises(Exception): with pytest.raises(Exception):
l1.start() l1.start()
l1.daemon.proc.wait() l1.daemon.proc.wait()
section("Verifying the node died with an error")
assert(l1.daemon.is_in_log(r'lost some state') is not None) assert(l1.daemon.is_in_log(r'lost some state') is not None)