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:
Rusty Russell 2017-06-20 15:08:03 +09:30
parent e7297ffd5d
commit e161c11e40
2 changed files with 11 additions and 10 deletions

View File

@ -616,15 +616,11 @@ class LegacyLightningDTests(BaseLightningDTests):
def test_multihop_payment(self):
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
# 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
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)

View File

@ -240,11 +240,13 @@ class LightningNode(object):
self.bitcoin = btc
self.executor = executor
# Use batch if you're doing more than one async.
def connect(self, remote_node, capacity, async=False):
# Collect necessary information
addr = self.rpc.newaddr()['address']
txid = self.bitcoin.rpc.sendtoaddress(addr, capacity)
tx = self.bitcoin.rpc.gettransaction(txid)
start_size = self.bitcoin.rpc.getmempoolinfo()['size']
def call_connect():
try:
@ -256,10 +258,13 @@ class LightningNode(object):
t.start()
def wait_connected():
# TODO(cdecker) Monitor the mempool to see if its time to generate yet.
time.sleep(5)
# The sleep should have given bitcoind time to add the tx to its mempool
# Up to 10 seconds to get tx into mempool.
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)
self.bitcoin.rpc.generate(1)
#fut.result(timeout=5)