pytest: make sure receiving peer's openingd is ready.

There's now a potential race: the source peer connect returns, but in
destination peer the master hasn't read the connect message from
connectd, so the peer isn't in listpeers yet.

(Previously the connection stayed in connectd, so there was no such
window).

This is an occasional issue in a few places.

Note that we take the opportunity to speed up test_disconnectpeer too
while we're there.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-08-09 09:55:19 +09:30 committed by Christian Decker
parent 50f5eb34b4
commit e59cbb3e2c
4 changed files with 8 additions and 3 deletions

View File

@ -1063,6 +1063,7 @@ def test_permfail_htlc_out(node_factory, bitcoind, executor):
l2 = node_factory.get_node(disconnect=disconnects)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
l2.daemon.wait_for_log('openingd-{} chan #1: Handed peer, entering loop'.format(l1.info['id']))
l2.fund_channel(l1, 10**6)
# This will fail at l2's end.

View File

@ -988,15 +988,14 @@ def test_disconnectpeer(node_factory, bitcoind):
assert len(l1.rpc.getpeer(l2.info['id'])['channels']) == 0
assert l1.rpc.getpeer(l3.info['id'])['connected']
assert len(l1.rpc.getpeer(l3.info['id'])['channels']) == 0
wait_for(lambda: l2.rpc.getpeer(l1.info['id']) is not None)
# Disconnect l2 from l1
l1.rpc.disconnect(l2.info['id'])
time.sleep(5)
# Make sure listpeers no longer returns the disconnected node
assert l1.rpc.getpeer(l2.info['id']) is None
assert l2.rpc.getpeer(l1.info['id']) is None
wait_for(lambda: l2.rpc.getpeer(l1.info['id']) is None)
# Make sure you cannot disconnect after disconnecting
with pytest.raises(RpcError, match=r'Peer not connected'):

View File

@ -348,6 +348,7 @@ def test_gossip_weirdalias(node_factory, bitcoind):
.format(normal_name))
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
l2.daemon.wait_for_log('openingd-{} chan #1: Handed peer, entering loop'.format(l1.info['id']))
l2.fund_channel(l1, 10**6)
bitcoind.rpc.generate(6)

View File

@ -744,7 +744,11 @@ class NodeFactory(object):
for src, dst in connections:
src.rpc.connect(dst.info['id'], 'localhost', dst.port)
# If we're returning now, make sure dst all show connections in
# getpeers.
if not fundchannel:
for src, dst in connections:
dst.daemon.wait_for_log('openingd-{} chan #[0-9]*: Handed peer, entering loop'.format(src.info['id']))
return nodes
# If we got here, we want to fund channels