Browse Source

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>
trytravis
Rusty Russell 6 years ago
parent
commit
1d7b287439
  1. 30
      tests/test_connection.py
  2. 27
      tests/utils.py

30
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'])

27
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):

Loading…
Cancel
Save