From d67fbbf94f2aa22a26956b8f844e211222952752 Mon Sep 17 00:00:00 2001 From: cthuang Date: Tue, 16 Mar 2021 10:39:58 +0000 Subject: [PATCH] TUN-4089: Address flakiness in component tests for termination --- component-tests/test_termination.py | 4 ++-- component-tests/util.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/component-tests/test_termination.py b/component-tests/test_termination.py index 765735ac..0d58496a 100644 --- a/component-tests/test_termination.py +++ b/component-tests/test_termination.py @@ -50,9 +50,9 @@ class TestTermination(): target=self.stream_request, args=(config, connected, True, )) in_flight_req.start() + with connected: + connected.wait(self.timeout) with self.within_grace_period(): - with connected: - connected.wait(self.timeout) # Send signal after the SSE connection is established self.terminate_by_signal(cloudflared, sig) self.wait_eyeball_thread(in_flight_req, self.grace_period) diff --git a/component-tests/util.py b/component-tests/util.py index 10100916..32023bf4 100644 --- a/component-tests/util.py +++ b/component-tests/util.py @@ -67,8 +67,12 @@ def wait_tunnel_ready(tunnel_url=None, require_min_connections=1): def check_tunnel_not_connected(): url = f'http://localhost:{METRICS_PORT}/ready' - resp = requests.get(url, timeout=1) - assert resp.status_code == 503, f"Expect {url} returns 503, got {resp.status_code}" + try: + resp = requests.get(url, timeout=1) + assert resp.status_code == 503, f"Expect {url} returns 503, got {resp.status_code}" + # cloudflared might already terminate + except requests.exceptions.ConnectionError as e: + LOGGER.warning(f"Failed to connect to {url}, error: {e}") # In some cases we don't need to check response status, such as when sending batch requests to generate logs