Skip to content

Commit f68feae

Browse files
rustyrussellendothermicdev
authored andcommitted
pytest: fix races now connecting is slightly slower.
We asserted that a node would be connected, but now we always call the chanbackup peer_connected hook, it might not be that fast: ``` 2025-05-17T08:37:58.7193306Z def test_funding_fail(node_factory, bitcoind): ... 2025-05-17T08:37:58.7204037Z # Restart l2 without ridiculous locktime. 2025-05-17T08:37:58.7204546Z del l2.daemon.opts['watchtime-blocks'] 2025-05-17T08:37:58.7204990Z l2.restart() 2025-05-17T08:37:58.7206578Z l1.rpc.connect(l2.info['id'], 'localhost', l2.port) 2025-05-17T08:37:58.7207072Z 2025-05-17T08:37:58.7207522Z # We don't have enough left to cover fees if we try to spend it all. 2025-05-17T08:37:58.7208203Z with pytest.raises(RpcError, match=r'not afford'): 2025-05-17T08:37:58.7208761Z l1.rpc.fundchannel(l2.info['id'], funds) 2025-05-17T08:37:58.7209203Z 2025-05-17T08:37:58.7209598Z # Should still be connected (we didn't contact the peer) 2025-05-17T08:37:58.7210243Z assert only_one(l1.rpc.listpeers()['peers'])['connected'] 2025-05-17T08:37:58.7210875Z l2.daemon.wait_for_log('Handed peer, entering loop') 2025-05-17T08:37:58.7211439Z > assert only_one(l2.rpc.listpeers()['peers'])['connected'] 2025-05-17T08:37:58.7211912Z E assert False ``` Signed-off-by: Rusty Russell <[email protected]>
1 parent b15100d commit f68feae

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

tests/test_connection.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def test_connect_basic(node_factory):
3030
l1id = l1.info['id']
3131
l2id = l2.info['id']
3232

33-
# These should be in openingd.
33+
# These should be in connectd.
3434
assert l1.rpc.getpeer(l2id)['connected']
35-
assert l2.rpc.getpeer(l1id)['connected']
35+
wait_for(lambda: l2.rpc.getpeer(l1id)['connected'])
3636
assert len(l1.rpc.listpeerchannels(l2id)['channels']) == 0
3737
assert len(l2.rpc.listpeerchannels(l1id)['channels']) == 0
3838

@@ -1145,15 +1145,14 @@ def test_funding_fail(node_factory, bitcoind):
11451145
del l2.daemon.opts['watchtime-blocks']
11461146
l2.restart()
11471147
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
1148+
wait_for(lambda: [p['connected'] for p in l2.rpc.listpeers()['peers']] == [True])
11481149

11491150
# We don't have enough left to cover fees if we try to spend it all.
11501151
with pytest.raises(RpcError, match=r'not afford'):
11511152
l1.rpc.fundchannel(l2.info['id'], funds)
11521153

11531154
# Should still be connected (we didn't contact the peer)
11541155
assert only_one(l1.rpc.listpeers()['peers'])['connected']
1155-
l2.daemon.wait_for_log('Handed peer, entering loop')
1156-
assert only_one(l2.rpc.listpeers()['peers'])['connected']
11571156

11581157
# This works.
11591158
l1.rpc.fundchannel(l2.info['id'], int(funds / 10))

0 commit comments

Comments
 (0)