From 1d7b287439d2efce6f3cb3eb51be8274a1971d89 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 22 Nov 2018 12:47:29 +1030 Subject: [PATCH] pytest: speed up test_restart_many_payments when !DEVELOPER. Because gossip in this case takes up to a minute, this test took 10 minutes. The workaround is to do the waiting-for-gossip all at once. Now it takes 362 seconds. Signed-off-by: Rusty Russell --- tests/test_connection.py | 30 ++++++++++++++++++++++++++++-- tests/utils.py | 27 ++++++++++++++------------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index ead73e409..f795c4f99 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1391,14 +1391,40 @@ def test_restart_many_payments(node_factory): inchans = [] for n in innodes: n.rpc.connect(l1.info['id'], 'localhost', l1.port) - inchans.append(n.fund_channel(l1, 10**6)) + inchans.append(n.fund_channel(l1, 10**6, False)) # Nodes with channels out of the main node outnodes = node_factory.get_nodes(len(innodes), opts={'may_reconnect': True}) outchans = [] for n in outnodes: n.rpc.connect(l1.info['id'], 'localhost', l1.port) - outchans.append(l1.fund_channel(n, 10**6)) + outchans.append(l1.fund_channel(n, 10**6, False)) + + # Now do all the waiting at once: if !DEVELOPER, this can be *very* slow! + l1_logs = [] + for i in range(len(innodes)): + scid = inchans[i] + l1_logs += [r'update for channel {}\(0\) now ACTIVE'.format(scid), + r'update for channel {}\(1\) now ACTIVE'.format(scid), + 'to CHANNELD_NORMAL'] + innodes[i].daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE' + .format(scid), + r'update for channel {}\(1\) now ACTIVE' + .format(scid), + 'to CHANNELD_NORMAL']) + + for i in range(len(outnodes)): + scid = outchans[i] + l1_logs += [r'update for channel {}\(0\) now ACTIVE'.format(scid), + r'update for channel {}\(1\) now ACTIVE'.format(scid), + 'to CHANNELD_NORMAL'] + outnodes[i].daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE' + .format(scid), + r'update for channel {}\(1\) now ACTIVE' + .format(scid), + 'to CHANNELD_NORMAL']) + + l1.daemon.wait_for_logs(l1_logs) # Manually create routes, get invoices Payment = namedtuple('Payment', ['innode', 'route', 'payment_hash']) diff --git a/tests/utils.py b/tests/utils.py index 152ee42eb..bdb09cbd1 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -493,7 +493,7 @@ class LightningNode(object): self.start() - def fund_channel(self, l2, amount): + def fund_channel(self, l2, amount, wait_for_active=True): # Give yourself some funds to work with addr = self.rpc.newaddr()['address'] @@ -524,18 +524,19 @@ class LightningNode(object): decoded2 = self.bitcoin.rpc.decoderawtransaction(tx) raise ValueError("Can't find {} payment in {} (1={} 2={})".format(amount, tx, decoded, decoded2)) - # We wait until gossipd sees both local updates, as well as status NORMAL, - # so it can definitely route through. - self.daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE' - .format(scid), - r'update for channel {}\(1\) now ACTIVE' - .format(scid), - 'to CHANNELD_NORMAL']) - l2.daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE' - .format(scid), - r'update for channel {}\(1\) now ACTIVE' - .format(scid), - 'to CHANNELD_NORMAL']) + if wait_for_active: + # We wait until gossipd sees both local updates, as well as status NORMAL, + # so it can definitely route through. + self.daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE' + .format(scid), + r'update for channel {}\(1\) now ACTIVE' + .format(scid), + 'to CHANNELD_NORMAL']) + l2.daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE' + .format(scid), + r'update for channel {}\(1\) now ACTIVE' + .format(scid), + 'to CHANNELD_NORMAL']) return scid def subd_pid(self, subd):