Skip to content

Commit

Permalink
pytest: test that we kick out pending transient connections too.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed May 14, 2024
1 parent 155311b commit dca361c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit dca361c

Please sign in to comment.