From ae5b98a727a272e349dc7d370bba7cf262fa514c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 29 Mar 2022 11:16:33 +1030 Subject: [PATCH] pytest: fix flake due to cln-grpc starting before "public key" message. e.g. ``` lightningd-1: 2022-03-28T11:02:12.476Z DEBUG plugin-cln-grpc: add_pem_file processed 1 valid and 0 invalid certs lightningd-1: 2022-03-28T11:02:12.478Z DEBUG plugin-cln-grpc: Connecting to \"lightning-rpc\" and serving grpc on 0.0.0.0:36331 lightningd-1: 2022-03-28T11:02:12.478Z DEBUG connectd: REPLY WIRE_CONNECTD_ACTIVATE_REPLY with 0 fds lightningd-1: 2022-03-28T11:02:12.478Z INFO lightningd: -------------------------------------------------- lightningd-1: 2022-03-28T11:02:12.478Z INFO lightningd: Server started with public key ``` Which means we don't see it, since start() swallows it: ``` > raise TimeoutError('Unable to find "{}" in logs.'.format(exs)) E TimeoutError: Unable to find "[re.compile('serving grpc on 0.0.0.0:')]" in logs. ``` Signed-off-by: Rusty Russell --- tests/test_cln_rs.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_cln_rs.py b/tests/test_cln_rs.py index edabc7c58..4fb62b810 100644 --- a/tests/test_cln_rs.py +++ b/tests/test_cln_rs.py @@ -15,6 +15,11 @@ pytestmark = pytest.mark.skipif( ) +def wait_for_grpc_start(node): + """This can happen before "public key" which start() swallows""" + wait_for(lambda: node.daemon.is_in_log(r'serving grpc on 0.0.0.0:')) + + def test_rpc_client(node_factory): l1 = node_factory.get_node() bin_path = Path.cwd() / "target" / "debug" / "examples" / "cln-rpc-getinfo" @@ -82,7 +87,7 @@ def test_grpc_connect(node_factory): certificate_chain=cert_path.open('rb').read() ) - l1.daemon.wait_for_log(r'serving grpc on 0.0.0.0:') + wait_for_grpc_start(l1) channel = grpc.secure_channel( f"localhost:{grpc_port}", creds, @@ -165,7 +170,7 @@ def test_grpc_wrong_auth(node_factory): "grpc-port": str(grpc_port), }) l1.start() - l1.daemon.wait_for_log(r'serving grpc on 0.0.0.0:') + wait_for_grpc_start(l1) def connect(node): p = Path(node.daemon.lightning_dir) / TEST_NETWORK @@ -193,7 +198,7 @@ def test_grpc_wrong_auth(node_factory): l1.stop() l2.start() - l2.daemon.wait_for_log(r'serving grpc on 0.0.0.0:') + wait_for_grpc_start(l2) # This should not work, it's a different node with pytest.raises(Exception, match=r'Socket closed|StatusCode.UNAVAILABLE'):