Skip to content

Commit

Permalink
CI: use fixed randomize ports, less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
pajod committed Sep 5, 2024
1 parent be64bde commit 49d3278
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/foreign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
with:
# need gcc: compile greenlet from source
# autoconf must pretend inotify unavail: libev FTBFS
# /tmp/.nginx must exist because nginx will not create configured tmp
prepare: |
pkg install pip-311 python-311 sqlite-3 nginx gcc13
usesh: true
Expand All @@ -80,6 +81,7 @@ jobs:
&& pkg info nginx \
&& gcc -dM -E - </dev/null \
&& ac_cv_header_sys_inotify_h=no ac_cv_func_inotify_init=no python3 -m pip install gevent \
&& mkdir -p /tmp/.nginx \
&& python3 -m pip install tox \
&& python3 -m tox --version \
&& python3 -m tox -e run-module \
Expand Down
9 changes: 7 additions & 2 deletions tests/test_nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
] # type: list[str|NamedTuple]

WORKER_DEPENDS = {
"sync": [],
"gthread": [],
"aiohttp.GunicornWebWorker": ["aiohttp"],
"aiohttp.GunicornUVLoopWebWorker": ["aiohttp", "uvloop"],
"uvicorn.workers.UvicornWorker": ["uvicorn"], # deprecated
Expand All @@ -66,6 +68,7 @@
}
DEP_WANTED = set(chain(*WORKER_DEPENDS.values())) # type: set[str]
DEP_INSTALLED = set() # type: set[str]
WORKER_ORDER = list(WORKER_DEPENDS.keys())

for dependency in DEP_WANTED:
try:
Expand Down Expand Up @@ -346,7 +349,7 @@ def __init__(
"gunicorn",
"--config=%s" % self.conf_path,
"--log-level=debug",
"--worker-class=%s" % worker_class,
"--worker-class=%s" % (worker_class, ),
"--workers=%d" % WORKER_COUNT,
# unsupported at the time this test was submitted
# "--buf-read-size=%d" % read_size,
Expand Down Expand Up @@ -388,7 +391,9 @@ def get(self, path):
@pytest.mark.parametrize("worker_class", TEST_SIMPLE)
def test_nginx_proxy(*, ssl, worker_class, dummy_ssl_cert, read_size=1024):
# avoid ports <= 6144 which may be in use by CI runner
fixed_port = 1024 * 6 + secrets.randbelow(1024 * 9)
# avoid quickly reusing ports as they might not be cleared immediately on BSD
worker_index = WORKER_ORDER.index(worker_class)
fixed_port = 1024 * 6 + (2 if ssl else 0) + (4 * worker_index)
# FIXME: should also test inherited socket (LISTEN_FDS)
# FIXME: should also test non-inherited (named) UNIX socket
gunicorn_bind = "[::1]:%d" % fixed_port
Expand Down

0 comments on commit 49d3278

Please sign in to comment.