Skip to content

Commit 148172e

Browse files
committed
fix tests
1 parent 09d27bf commit 148172e

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/common/gunicorn/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
import typing
88

9+
from prometheus_client.multiprocess import mark_process_dead
10+
911
if typing.TYPE_CHECKING: # pragma: no cover
1012
from gunicorn.arbiter import Arbiter # type: ignore[import-untyped]
1113
from gunicorn.workers.base import Worker # type: ignore[import-untyped]
1214

1315

1416
def worker_exit(server: "Arbiter", worker: "Worker") -> None:
1517
"""Detach the process Prometheus metrics collector when a worker exits."""
16-
from prometheus_client import multiprocess
17-
18-
multiprocess.mark_process_dead(worker.pid) # type: ignore[no-untyped-call]
18+
mark_process_dead(worker.pid) # type: ignore[no-untyped-call]

src/common/gunicorn/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def load_config(self) -> None:
4141
if key in cfg_settings
4242
)
4343
for key, value in options_items:
44-
print(f"setting {key=} {value=}")
4544
self.cfg.set(key.lower(), value)
4645
self.load_config_from_module_name_or_filename(self.cfg.config)
4746

tests/unit/common/gunicorn/test_logging.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ def test_gunicorn_prometheus_gunicorn_logger__expected_metrics(
8686
logger = PrometheusGunicornLogger(config)
8787

8888
response_mock = mocker.Mock()
89-
response_mock.status = 200
89+
response_mock.status = b"200 OK"
90+
response_mock.status_code = 200
9091

9192
# When
9293
logger.access(
9394
response_mock,
9495
mocker.Mock(),
95-
{"PATH_INFO": "/health", "REQUEST_METHOD": "GET"},
96+
{"wsgi.django_route": "^health", "REQUEST_METHOD": "GET"},
9697
timedelta(milliseconds=101),
9798
)
9899

tests/unit/common/gunicorn/test_utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ def test_django_wsgi_application__defaults__expected_config(
3535
assert app.load_wsgiapp() == wsgi_handler_mock
3636

3737

38-
def test_run_server__expected_config() -> None:
38+
def test_run_server__default_config_file__runs_expected(
39+
mocker: pytest_mock.MockerFixture,
40+
) -> None:
3941
# Given
42+
# prevent real forking from Gunicorn
43+
mocker.patch("os.fork").return_value = 0
44+
mark_process_dead_mock = mocker.patch("common.gunicorn.conf.mark_process_dead")
45+
4046
def delay_kill(pid: int = os.getpid()) -> None:
4147
time.sleep(0.1)
4248
os.kill(pid, signal.SIGTERM)
@@ -48,6 +54,4 @@ def delay_kill(pid: int = os.getpid()) -> None:
4854
run_server()
4955

5056
# Then
51-
from prometheus_client import multiprocess
52-
53-
multiprocess.mark_process_dead
57+
mark_process_dead_mock.assert_called()

0 commit comments

Comments
 (0)