mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
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:
@@ -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'])
|
||||||
|
|||||||
@@ -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,18 +524,19 @@ 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))
|
||||||
|
|
||||||
# We wait until gossipd sees both local updates, as well as status NORMAL,
|
if wait_for_active:
|
||||||
# so it can definitely route through.
|
# We wait until gossipd sees both local updates, as well as status NORMAL,
|
||||||
self.daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE'
|
# so it can definitely route through.
|
||||||
.format(scid),
|
self.daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE'
|
||||||
r'update for channel {}\(1\) now ACTIVE'
|
.format(scid),
|
||||||
.format(scid),
|
r'update for channel {}\(1\) now ACTIVE'
|
||||||
'to CHANNELD_NORMAL'])
|
.format(scid),
|
||||||
l2.daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE'
|
'to CHANNELD_NORMAL'])
|
||||||
.format(scid),
|
l2.daemon.wait_for_logs([r'update for channel {}\(0\) now ACTIVE'
|
||||||
r'update for channel {}\(1\) now ACTIVE'
|
.format(scid),
|
||||||
.format(scid),
|
r'update for channel {}\(1\) now ACTIVE'
|
||||||
'to CHANNELD_NORMAL'])
|
.format(scid),
|
||||||
|
'to CHANNELD_NORMAL'])
|
||||||
return scid
|
return scid
|
||||||
|
|
||||||
def subd_pid(self, subd):
|
def subd_pid(self, subd):
|
||||||
|
|||||||
Reference in New Issue
Block a user