mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 00:54:20 +01:00
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:
committed by
Rusty Russell
parent
3fefd5f46d
commit
29785d4990
@@ -858,6 +858,35 @@ class LightningDTests(BaseLightningDTests):
|
|||||||
c.execute('SELECT COUNT(*) FROM outputs WHERE status=2')
|
c.execute('SELECT COUNT(*) FROM outputs WHERE status=2')
|
||||||
assert(c.fetchone()[0] == 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):
|
class LegacyLightningDTests(BaseLightningDTests):
|
||||||
|
|
||||||
def test_connect(self):
|
def test_connect(self):
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ class TailableProc(object):
|
|||||||
def __init__(self, outputDir=None):
|
def __init__(self, outputDir=None):
|
||||||
self.logs = []
|
self.logs = []
|
||||||
self.logs_cond = threading.Condition(threading.RLock())
|
self.logs_cond = threading.Condition(threading.RLock())
|
||||||
self.thread = threading.Thread(target=self.tail)
|
|
||||||
self.thread.daemon = True
|
|
||||||
self.cmd_line = None
|
self.cmd_line = None
|
||||||
self.running = False
|
self.running = False
|
||||||
self.proc = None
|
self.proc = None
|
||||||
@@ -55,6 +53,8 @@ class TailableProc(object):
|
|||||||
"""
|
"""
|
||||||
logging.debug("Starting '%s'", " ".join(self.cmd_line))
|
logging.debug("Starting '%s'", " ".join(self.cmd_line))
|
||||||
self.proc = subprocess.Popen(self.cmd_line, stdout=subprocess.PIPE)
|
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.thread.start()
|
||||||
self.running = True
|
self.running = True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user