Skip to content

Commit 0e58508

Browse files
aborgatinclaude
authored andcommitted
test: Use an instant stand-in process in the worker-exit test
The spawned metrics server did not come up within 30 s inside the full unit suite on macOS CI. The test is about the process surviving a forked child's exit, not about serving HTTP, so register a fork-context daemon process via start_metrics_server instead and assert it is still alive after the child runs multiprocessing.util._exit_function(). Without the fix it is terminated (exitcode -SIGTERM). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Alexandr Borgatin <a.borgatin@yandex.ru>
1 parent 2d0d723 commit 0e58508

1 file changed

Lines changed: 16 additions & 30 deletions

File tree

‎sdk/python/tests/unit/test_metrics.py‎

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -652,42 +652,29 @@ class TestMetricsProcessSurvivesForkedChildExit:
652652
"""A forked child (e.g. a Gunicorn worker) must not terminate the metrics server on exit."""
653653

654654
def test_forked_child_exit_does_not_terminate_metrics_process(self):
655+
import multiprocessing
655656
import multiprocessing.util
656657

657658
import feast.metrics as m
658659

659-
with socket.socket() as s:
660-
s.bind(("127.0.0.1", 0))
661-
port = s.getsockname()[1]
662-
663-
m.start_metrics_server(
664-
MagicMock(),
665-
port=port,
666-
start_resource_monitoring=False,
667-
start_freshness_monitoring=False,
660+
# Stand-in for the metrics-server process: a real daemon process that
661+
# starts instantly on every platform, registered by start_metrics_server.
662+
proc = multiprocessing.get_context("fork").Process(
663+
target=time.sleep, args=(60,), daemon=True
668664
)
669-
proc = m._metrics_process
670-
671-
def metrics_status():
672-
conn = http.client.HTTPConnection("127.0.0.1", port, timeout=5)
673-
try:
674-
conn.request("GET", "/metrics")
675-
return conn.getresponse().status
676-
finally:
677-
conn.close()
665+
mock_event = MagicMock()
666+
mock_event.wait.return_value = True
678667

668+
with (
669+
patch("feast.metrics.multiprocessing.Process", return_value=proc),
670+
patch("feast.metrics.multiprocessing.Event", return_value=mock_event),
671+
):
672+
m.start_metrics_server(
673+
MagicMock(),
674+
start_resource_monitoring=False,
675+
start_freshness_monitoring=False,
676+
)
679677
try:
680-
# The child process can take a while to start (spawn on macOS)
681-
deadline = time.monotonic() + 30
682-
while True:
683-
try:
684-
assert metrics_status() == 200
685-
break
686-
except ConnectionError:
687-
if time.monotonic() > deadline:
688-
raise
689-
time.sleep(0.2)
690-
691678
pid = os.fork()
692679
if pid == 0:
693680
# What a worker runs at interpreter exit
@@ -697,7 +684,6 @@ def metrics_status():
697684

698685
proc.join(timeout=1)
699686
assert proc.is_alive()
700-
assert metrics_status() == 200
701687
finally:
702688
proc.terminate()
703689
proc.join(timeout=5)

0 commit comments

Comments
 (0)