Skip to content

Fix integration tests #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/gunicorn_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import concurrent.futures
import contextlib
import multiprocessing
import time
from typing import Iterator

from gunicorn.app.wsgiapp import WSGIApplication
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()