Skip to content

Commit e85a276

Browse files
committed
pytest: fix flake in test_connect_ratelimit.
Sometimes they connect too fast, so we don't get a chance to ratelimit all of them: ``` def test_connect_ratelimit(node_factory, bitcoind): """l1 has 5 peers, restarts, make sure we limit""" nodes = node_factory.get_nodes(6, opts=[{'dev-limit-connections-inflight': None, 'may_reconnect': True}] + [{'may_reconnect': True}] * 5) l1 = nodes[0] nodes = nodes[1:] addr = l1.rpc.newaddr()['bech32'] for n in nodes: bitcoind.rpc.sendtoaddress(addr, (FUNDAMOUNT + 1000000) / 10**8) bitcoind.generate_block(1, wait_for_mempool=len(nodes)) sync_blockheight(bitcoind, [l1]) for n in nodes: l1.rpc.connect(n.info['id'], 'localhost', n.port) l1.rpc.fundchannel(n.info['id'], FUNDAMOUNT) # Make sure all channels are established and announced. bitcoind.generate_block(6, wait_for_mempool=len(nodes)) wait_for(lambda: len(l1.rpc.listchannels()['channels']) == len(nodes) * 2) assert not l1.daemon.is_in_log('Unblocking for') l1.restart() # The first will be ok, but others should block and be unblocked. > l1.daemon.wait_for_logs((['Unblocking for '] + ['Too many connections, waiting']) * (len(nodes) - 1)) tests/test_connection.py:4721: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pyln.testing.utils.LightningD object at 0x7f6e288a3a60> regexs = ['Unblocking for ', 'Too many connections, waiting', 'Unblocking for ', 'Too many connections, waiting', 'Unblocking for ', 'Too many connections, waiting', ...] timeout = 180 def wait_for_logs(self, regexs, timeout=TIMEOUT): """Look for `regexs` in the logs. The logs contain tailed stdout of the process. We look for each regex in `regexs`, starting from `logsearch_start` which normally is the position of the last found entry of a previous wait-for logs call. The ordering inside `regexs` doesn't matter. We fail if the timeout is exceeded or if the underlying process exits before all the `regexs` were found. If timeout is None, no time-out is applied. """ logging.debug("Waiting for {} in the logs".format(regexs)) exs = [re.compile(r) for r in regexs] start_time = time.time() while True: if self.logsearch_start >= len(self.logs): if not self.logs_catchup(): time.sleep(0.25) if timeout is not None and time.time() > start_time + timeout: print("Time-out: can't find {} in logs".format(exs)) for r in exs: if self.is_in_log(r): print("({} was previously in logs!)".format(r)) > raise TimeoutError('Unable to find "{}" in logs.'.format(exs)) E TimeoutError: Unable to find "[re.compile('Unblocking for '), re.compile('Too many connections, waiting')]" in logs. ``` Signed-off-by: Rusty Russell <[email protected]>
1 parent 5f3eef5 commit e85a276

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/test_connection.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import time
2222
import unittest
2323
import websocket
24+
import signal
2425
import ssl
2526

2627

@@ -4715,13 +4716,21 @@ def test_connect_ratelimit(node_factory, bitcoind):
47154716

47164717
assert not l1.daemon.is_in_log('Unblocking for')
47174718

4718-
l1.restart()
4719+
l1.stop()
4720+
# Suspend the others, to make sure they cannot respond too fast.
4721+
for n in nodes:
4722+
os.kill(n.daemon.proc.pid, signal.SIGSTOP)
4723+
l1.start()
47194724

47204725
# The first will be ok, but others should block and be unblocked.
47214726
l1.daemon.wait_for_logs((['Unblocking for ']
47224727
+ ['Too many connections, waiting'])
47234728
* (len(nodes) - 1))
47244729

4730+
# Resume them
4731+
for n in nodes:
4732+
os.kill(n.daemon.proc.pid, signal.SIGCONT)
4733+
47254734
# And now they're all connected
47264735
wait_for(lambda: [p['connected'] for p in l1.rpc.listpeers()['peers']] == [True] * len(nodes))
47274736

0 commit comments

Comments
 (0)