Skip to content

Commit

Permalink
Merge #180 - fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkKoz authored Jun 23, 2023
2 parents 743c40c + 3a10f40 commit 3888578
Showing 1 changed file with 18 additions and 0 deletions.
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()

0 comments on commit 3888578

Please sign in to comment.