diff options
author | 2023-06-23 16:39:00 -0700 | |
---|---|---|
committer | 2023-06-23 16:39:00 -0700 | |
commit | 38885785334c5b77748f1b4767ef44124cb4dd3f (patch) | |
tree | 135c608a44e82e0efa8270592bfce33fd9806269 /tests/gunicorn_utils.py | |
parent | Merge pull request #178 from python-discord/fix-status-badge (diff) | |
parent | Kill process after waiting for it to terminate (diff) |
Merge #180 - fix integration tests
Diffstat (limited to 'tests/gunicorn_utils.py')
-rw-r--r-- | tests/gunicorn_utils.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/gunicorn_utils.py b/tests/gunicorn_utils.py index 5c077aa..7af0767 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 @@ -33,6 +34,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 @@ -77,4 +84,15 @@ 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 process ended or the timeout was reached, + # so kill the process afterwards to be sure. + proc.join(timeout=10) + proc.kill() |