Skip to content

Commit 3888578

Browse files
authored
Merge #180 - fix integration tests
2 parents 743c40c + 3a10f40 commit 3888578

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/gunicorn_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import concurrent.futures
22
import contextlib
33
import multiprocessing
4+
import time
45
from typing import Iterator
56

67
from gunicorn.app.wsgiapp import WSGIApplication
@@ -33,6 +34,12 @@ def _proc_target(config_path: str, event: multiprocessing.Event, **kwargs) -> No
3334
def when_ready(_):
3435
event.set()
3536

37+
# Clear sys.argv to prevent Gunicorn from trying to interpret the command arguments
38+
# used to run the test as it's own arguments.
39+
import sys
40+
41+
sys.argv = [""]
42+
3643
app = _StandaloneApplication(config_path, when_ready=when_ready, **kwargs)
3744

3845
import logging
@@ -77,4 +84,15 @@ def run_gunicorn(config_path: str = "config/gunicorn.conf.py", **kwargs) -> Iter
7784

7885
yield
7986
finally:
87+
# See https://github.com/python-discord/snekbox/issues/177
88+
# Sleeping before terminating the process avoids a case where
89+
# terminating the process can take >30 seconds.
90+
time.sleep(0.2)
91+
8092
proc.terminate()
93+
94+
# Actually wait for the process to finish. There doesn't seem to be a
95+
# reliable way of checking if process ended or the timeout was reached,
96+
# so kill the process afterwards to be sure.
97+
proc.join(timeout=10)
98+
proc.kill()

0 commit comments

Comments
 (0)