mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
tests/utils.py: poll mempool instead of sleeping.
On my laptop under load, 5 seconds was no longer enough for legacy. But this breaks async (they all see mempool increase, and fire prematurely), so stop doing that. I can't get this test to work at all, in fact, without this patch. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -616,15 +616,11 @@ class LegacyLightningDTests(BaseLightningDTests):
|
|||||||
|
|
||||||
def test_multihop_payment(self):
|
def test_multihop_payment(self):
|
||||||
nodes = [self.node_factory.get_node() for _ in range(5)]
|
nodes = [self.node_factory.get_node() for _ in range(5)]
|
||||||
conn_futures = [nodes[i].connect(nodes[i+1], 0.01, async=True) for i in range(len(nodes)-1)]
|
for i in range(len(nodes)-1):
|
||||||
|
nodes[i].connect(nodes[i+1], 0.01)
|
||||||
|
|
||||||
htlc_amount = 10000
|
htlc_amount = 10000
|
||||||
|
|
||||||
# Now wait for all of them
|
|
||||||
[f.result() for f in conn_futures]
|
|
||||||
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
# Manually add channel l2 -> l3 to l1 so that it can compute the route
|
# Manually add channel l2 -> l3 to l1 so that it can compute the route
|
||||||
for i in range(len(nodes)-1):
|
for i in range(len(nodes)-1):
|
||||||
nodes[0].rpc.dev_add_route(nodes[i].info['id'], nodes[i+1].info['id'], 1, 1, 6, 6)
|
nodes[0].rpc.dev_add_route(nodes[i].info['id'], nodes[i+1].info['id'], 1, 1, 6, 6)
|
||||||
|
|||||||
@@ -240,11 +240,13 @@ class LightningNode(object):
|
|||||||
self.bitcoin = btc
|
self.bitcoin = btc
|
||||||
self.executor = executor
|
self.executor = executor
|
||||||
|
|
||||||
|
# Use batch if you're doing more than one async.
|
||||||
def connect(self, remote_node, capacity, async=False):
|
def connect(self, remote_node, capacity, async=False):
|
||||||
# Collect necessary information
|
# Collect necessary information
|
||||||
addr = self.rpc.newaddr()['address']
|
addr = self.rpc.newaddr()['address']
|
||||||
txid = self.bitcoin.rpc.sendtoaddress(addr, capacity)
|
txid = self.bitcoin.rpc.sendtoaddress(addr, capacity)
|
||||||
tx = self.bitcoin.rpc.gettransaction(txid)
|
tx = self.bitcoin.rpc.gettransaction(txid)
|
||||||
|
start_size = self.bitcoin.rpc.getmempoolinfo()['size']
|
||||||
|
|
||||||
def call_connect():
|
def call_connect():
|
||||||
try:
|
try:
|
||||||
@@ -256,10 +258,13 @@ class LightningNode(object):
|
|||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
def wait_connected():
|
def wait_connected():
|
||||||
# TODO(cdecker) Monitor the mempool to see if its time to generate yet.
|
# Up to 10 seconds to get tx into mempool.
|
||||||
time.sleep(5)
|
start_time = time.time()
|
||||||
|
while self.bitcoin.rpc.getmempoolinfo()['size'] == start_size:
|
||||||
|
if time.time() > start_time + 10:
|
||||||
|
raise TimeoutError('No new transactions in mempool')
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
# The sleep should have given bitcoind time to add the tx to its mempool
|
|
||||||
self.bitcoin.rpc.generate(1)
|
self.bitcoin.rpc.generate(1)
|
||||||
|
|
||||||
#fut.result(timeout=5)
|
#fut.result(timeout=5)
|
||||||
|
|||||||
Reference in New Issue
Block a user