TUN-4112: Skip testing graceful shutdown with SIGINT on Windows

This commit is contained in:
cthuang 2021-03-23 17:24:36 +00:00 committed by Chung Ting Huang
parent 6106737281
commit 12447677cf
1 changed files with 48 additions and 40 deletions

View File

@ -1,11 +1,20 @@
#!/usr/bin/env python #!/usr/bin/env python
from contextlib import contextmanager from contextlib import contextmanager
import requests import platform
import signal import signal
import threading import threading
import time import time
from util import start_cloudflared, wait_tunnel_ready, check_tunnel_not_connected, LOGGER import pytest
import requests
from util import start_cloudflared, wait_tunnel_ready, check_tunnel_not_connected
def supported_signals():
if platform.system() == "Windows":
return [signal.SIGTERM]
return [signal.SIGTERM, signal.SIGINT]
class TestTermination(): class TestTermination():
@ -14,57 +23,56 @@ class TestTermination():
extra_config = { extra_config = {
"grace-period": f"{grace_period}s", "grace-period": f"{grace_period}s",
} }
signals = [signal.SIGTERM, signal.SIGINT]
sse_endpoint = "/sse?freq=1s" sse_endpoint = "/sse?freq=1s"
def test_graceful_shutdown(self, tmp_path, component_tests_config): @pytest.mark.parametrize("signal", supported_signals())
def test_graceful_shutdown(self, tmp_path, component_tests_config, signal):
config = component_tests_config(self.extra_config) config = component_tests_config(self.extra_config)
for sig in self.signals: with start_cloudflared(
with start_cloudflared( tmp_path, config, new_process=True, capture_output=False) as cloudflared:
tmp_path, config, new_process=True, capture_output=False) as cloudflared: wait_tunnel_ready(tunnel_url=config.get_url())
wait_tunnel_ready(tunnel_url=config.get_url())
connected = threading.Condition() connected = threading.Condition()
in_flight_req = threading.Thread( in_flight_req = threading.Thread(
target=self.stream_request, args=(config, connected,)) target=self.stream_request, args=(config, connected, False, ))
in_flight_req.start() in_flight_req.start()
with connected: with connected:
connected.wait(self.timeout) connected.wait(self.timeout)
# Send signal after the SSE connection is established # Send signal after the SSE connection is established
self.terminate_by_signal(cloudflared, sig) self.terminate_by_signal(cloudflared, signal)
self.wait_eyeball_thread( self.wait_eyeball_thread(
in_flight_req, self.grace_period + self.timeout) in_flight_req, self.grace_period + self.timeout)
# test cloudflared terminates before grace period expires when all eyeball # test cloudflared terminates before grace period expires when all eyeball
# connections are drained # connections are drained
def test_shutdown_once_no_connection(self, tmp_path, component_tests_config): @pytest.mark.parametrize("signal", supported_signals())
def test_shutdown_once_no_connection(self, tmp_path, component_tests_config, signal):
config = component_tests_config(self.extra_config) config = component_tests_config(self.extra_config)
for sig in self.signals: with start_cloudflared(
with start_cloudflared( tmp_path, config, new_process=True, capture_output=False) as cloudflared:
tmp_path, config, new_process=True, capture_output=False) as cloudflared: wait_tunnel_ready(tunnel_url=config.get_url())
wait_tunnel_ready(tunnel_url=config.get_url())
connected = threading.Condition() connected = threading.Condition()
in_flight_req = threading.Thread( in_flight_req = threading.Thread(
target=self.stream_request, args=(config, connected, True, )) target=self.stream_request, args=(config, connected, True, ))
in_flight_req.start() in_flight_req.start()
with connected: with connected:
connected.wait(self.timeout) connected.wait(self.timeout)
with self.within_grace_period(): with self.within_grace_period():
# Send signal after the SSE connection is established # Send signal after the SSE connection is established
self.terminate_by_signal(cloudflared, sig) self.terminate_by_signal(cloudflared, signal)
self.wait_eyeball_thread(in_flight_req, self.grace_period) self.wait_eyeball_thread(in_flight_req, self.grace_period)
def test_no_connection_shutdown(self, tmp_path, component_tests_config): @pytest.mark.parametrize("signal", supported_signals())
def test_no_connection_shutdown(self, tmp_path, component_tests_config, signal):
config = component_tests_config(self.extra_config) config = component_tests_config(self.extra_config)
for sig in self.signals: with start_cloudflared(
with start_cloudflared( tmp_path, config, new_process=True, capture_output=False) as cloudflared:
tmp_path, config, new_process=True, capture_output=False) as cloudflared: wait_tunnel_ready(tunnel_url=config.get_url())
wait_tunnel_ready(tunnel_url=config.get_url()) with self.within_grace_period():
with self.within_grace_period(): self.terminate_by_signal(cloudflared, signal)
self.terminate_by_signal(cloudflared, sig)
def terminate_by_signal(self, cloudflared, sig): def terminate_by_signal(self, cloudflared, sig):
cloudflared.send_signal(sig) cloudflared.send_signal(sig)