pytest: Added a simple channel-persistence test

This test opens a channel, stops the nodes and the restarts them to
see if we can successfully reload the channel state from the database.
This commit is contained in:
Christian Decker 2017-08-14 16:52:19 +02:00 committed by Rusty Russell
parent 3fefd5f46d
commit 29785d4990
2 changed files with 31 additions and 2 deletions

View File

@ -858,6 +858,35 @@ class LightningDTests(BaseLightningDTests):
c.execute('SELECT COUNT(*) FROM outputs WHERE status=2')
assert(c.fetchone()[0] == 2)
def test_channel_persistence(self):
# Start two nodes and open a channel (to remember)
l1, l2 = self.connect()
# Neither node should have a channel open, they are just connected
for n in (l1, l2):
assert(n.db_query('SELECT COUNT(id) as count FROM channels;')[0]['count'] == 0)
self.fund_channel(l1, l2, 100000)
peers = l1.rpc.getpeers()['peers']
assert(len(peers) == 1 and peers[0]['state'] == 'CHANNELD_NORMAL')
# Both nodes should now have exactly one channel in the database
for n in (l1, l2):
assert(n.db_query('SELECT COUNT(id) as count FROM channels;')[0]['count'] == 1)
l1.daemon.stop()
# Let the other side notice, then stop it
wait_for(lambda: not l2.rpc.getpeers()['peers'][0]['connected'])
l2.daemon.stop()
# Now restart l1 and it should reload peers/channels from the DB
l1.daemon.start()
#wait_for(lambda: len(l1.rpc.getpeers()['peers']) == 1)
class LegacyLightningDTests(BaseLightningDTests):
def test_connect(self):

View File

@ -42,8 +42,6 @@ class TailableProc(object):
def __init__(self, outputDir=None):
self.logs = []
self.logs_cond = threading.Condition(threading.RLock())
self.thread = threading.Thread(target=self.tail)
self.thread.daemon = True
self.cmd_line = None
self.running = False
self.proc = None
@ -55,6 +53,8 @@ class TailableProc(object):
"""
logging.debug("Starting '%s'", " ".join(self.cmd_line))
self.proc = subprocess.Popen(self.cmd_line, stdout=subprocess.PIPE)
self.thread = threading.Thread(target=self.tail)
self.thread.daemon = True
self.thread.start()
self.running = True