pytest: test that we kick out pending transient connections too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-05-14 14:02:47 +09:30
parent 155311b053
commit dca361c5c7

View file

@ -4617,3 +4617,35 @@ def test_connect_transient(node_factory):
l1.rpc.connect(l4.info['id'], 'localhost', l4.port)
assert l1.rpc.listpeers(l3.info['id'])['peers'] == []
assert l1.daemon.is_in_log(fr"due to stress, randomly closing peer {l3.info['id']} \(score 0\)")
def test_connect_transient_pending(node_factory, bitcoind, executor):
"""Test that we kick out in-connection transient connections"""
l1, l2, l3, l4 = node_factory.get_nodes(4, opts=[{},
{'dev-handshake-no-reply': None},
{'dev-handshake-no-reply': None},
{}])
# This will block...
fut1 = executor.submit(l1.rpc.connect, l2.info['id'], 'localhost', l2.port)
fut2 = executor.submit(l1.rpc.connect, l3.info['id'], 'localhost', l3.port)
assert not l1.daemon.is_in_log("due to stress, closing transient connect attempt")
# Wait until those connects in progress.
l2.daemon.wait_for_log("Connect IN")
l3.daemon.wait_for_log("Connect IN")
# Now force exhaustion.
l1.rpc.dev_connectd_exhaust_fds()
# This one will kick out one of the others.
l1.rpc.connect(l4.info['id'], 'localhost', l4.port)
line = l1.daemon.wait_for_log("due to stress, closing transient connect attempt")
peerid = re.search(r'due to stress, closing transient connect attempt to (.*)', line).groups()[0]
with pytest.raises(RpcError, match="Terminated due to too many connections"):
if peerid == l2.info['id']:
fut1.result(TIMEOUT)
else:
fut2.result(TIMEOUT)