From 283130f971f8ed5d40da024013812fa104285690 Mon Sep 17 00:00:00 2001 From: wookie184 Date: Thu, 22 Jun 2023 12:48:25 +0000 Subject: [PATCH 1/3] Fix issue when running individual integration tests --- tests/gunicorn_utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/gunicorn_utils.py b/tests/gunicorn_utils.py index 5c077aaf..15a2b589 100644 --- a/tests/gunicorn_utils.py +++ b/tests/gunicorn_utils.py @@ -33,6 +33,12 @@ def _proc_target(config_path: str, event: multiprocessing.Event, **kwargs) -> No def when_ready(_): event.set() + # Clear sys.argv to prevent Gunicorn from trying to interpret the command arguments + # used to run the test as it's own arguments. + import sys + + sys.argv = [""] + app = _StandaloneApplication(config_path, when_ready=when_ready, **kwargs) import logging From 17c95e8a2e4a2788e43fb38d0ec116201db69524 Mon Sep 17 00:00:00 2001 From: wookie184 Date: Thu, 22 Jun 2023 12:49:29 +0000 Subject: [PATCH 2/3] Attempt to fix flaky integration tests --- tests/gunicorn_utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/gunicorn_utils.py b/tests/gunicorn_utils.py index 15a2b589..54a51dff 100644 --- a/tests/gunicorn_utils.py +++ b/tests/gunicorn_utils.py @@ -1,6 +1,7 @@ import concurrent.futures import contextlib import multiprocessing +import time from typing import Iterator from gunicorn.app.wsgiapp import WSGIApplication @@ -83,4 +84,14 @@ def run_gunicorn(config_path: str = "config/gunicorn.conf.py", **kwargs) -> Iter yield finally: + # See https://github.com/python-discord/snekbox/issues/177 + # Sleeping before terminating the process avoids a case where + # terminating the process can take >30 seconds. + time.sleep(0.2) + proc.terminate() + + # Actually wait for the process to finish. There doesn't seem to be a + # reliable way of checking if the timeout was reached or this ended normally, + # but if the timeout is reached it will probably error later anyway. + proc.join(timeout=10) From 3a10f404064eb520d5f6ac882dc5e9429654ef8b Mon Sep 17 00:00:00 2001 From: wookie184 Date: Fri, 23 Jun 2023 10:42:38 +0000 Subject: [PATCH 3/3] Kill process after waiting for it to terminate --- tests/gunicorn_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/gunicorn_utils.py b/tests/gunicorn_utils.py index 54a51dff..7af07676 100644 --- a/tests/gunicorn_utils.py +++ b/tests/gunicorn_utils.py @@ -92,6 +92,7 @@ def run_gunicorn(config_path: str = "config/gunicorn.conf.py", **kwargs) -> Iter proc.terminate() # Actually wait for the process to finish. There doesn't seem to be a - # reliable way of checking if the timeout was reached or this ended normally, - # but if the timeout is reached it will probably error later anyway. + # reliable way of checking if process ended or the timeout was reached, + # so kill the process afterwards to be sure. proc.join(timeout=10) + proc.kill()