TUN-4089: Address flakiness in component tests for termination

This commit is contained in:
cthuang 2021-03-16 10:39:58 +00:00
parent 39901e1d60
commit d67fbbf94f
2 changed files with 8 additions and 4 deletions

View File

@ -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)

View File

@ -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