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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-11-22 12:47:29 +10:30
parent d9d762170a
commit 1d7b287439
2 changed files with 42 additions and 15 deletions

View File

@@ -1391,14 +1391,40 @@ def test_restart_many_payments(node_factory):
inchans = [] inchans = []
for n in innodes: for n in innodes:
n.rpc.connect(l1.info['id'], 'localhost', l1.port) 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 # Nodes with channels out of the main node
outnodes = node_factory.get_nodes(len(innodes), opts={'may_reconnect': True}) outnodes = node_factory.get_nodes(len(innodes), opts={'may_reconnect': True})
outchans = [] outchans = []
for n in outnodes: for n in outnodes:
n.rpc.connect(l1.info['id'], 'localhost', l1.port) 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 # Manually create routes, get invoices
Payment = namedtuple('Payment', ['innode', 'route', 'payment_hash']) Payment = namedtuple('Payment', ['innode', 'route', 'payment_hash'])

View File

@@ -493,7 +493,7 @@ class LightningNode(object):
self.start() 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 # Give yourself some funds to work with
addr = self.rpc.newaddr()['address'] addr = self.rpc.newaddr()['address']
@@ -524,6 +524,7 @@ class LightningNode(object):
decoded2 = self.bitcoin.rpc.decoderawtransaction(tx) decoded2 = self.bitcoin.rpc.decoderawtransaction(tx)
raise ValueError("Can't find {} payment in {} (1={} 2={})".format(amount, tx, decoded, decoded2)) raise ValueError("Can't find {} payment in {} (1={} 2={})".format(amount, tx, decoded, decoded2))
if wait_for_active:
# We wait until gossipd sees both local updates, as well as status NORMAL, # We wait until gossipd sees both local updates, as well as status NORMAL,
# so it can definitely route through. # so it can definitely route through.
self.daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE' self.daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE'