Skip to content

Commit 125f4e8

Browse files
aborgatinclaude
authored andcommitted
test: Check active_children() in the forked child instead of running _exit_function
Running multiprocessing.util._exit_function() in a fork of the pytest process runs every registered finalizer. Check what a worker's exit would act on instead: the metrics process must not be in the child's active_children(). Also cover _forget_metrics_process_in_child directly, and kill the stand-in process in cleanup (terminate() can wait out the join timeout under xdist). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Alexandr Borgatin <a.borgatin@yandex.ru>
1 parent 0e58508 commit 125f4e8

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,8 @@ def test_ready_event_set_on_successful_bind(self):
651651
class TestMetricsProcessSurvivesForkedChildExit:
652652
"""A forked child (e.g. a Gunicorn worker) must not terminate the metrics server on exit."""
653653

654-
def test_forked_child_exit_does_not_terminate_metrics_process(self):
654+
def test_forked_child_does_not_track_metrics_process(self):
655655
import multiprocessing
656-
import multiprocessing.util
657656

658657
import feast.metrics as m
659658

@@ -677,19 +676,35 @@ def test_forked_child_exit_does_not_terminate_metrics_process(self):
677676
try:
678677
pid = os.fork()
679678
if pid == 0:
680-
# What a worker runs at interpreter exit
681-
multiprocessing.util._exit_function()
682-
os._exit(0)
683-
os.waitpid(pid, 0)
679+
# A worker's interpreter exit terminates every daemon process in
680+
# active_children(); report whether the metrics process is in it.
681+
tracked = proc in multiprocessing.active_children()
682+
os._exit(1 if tracked else 0)
683+
_, status = os.waitpid(pid, 0)
684684

685-
proc.join(timeout=1)
685+
assert os.waitstatus_to_exitcode(status) == 0
686686
assert proc.is_alive()
687687
finally:
688-
proc.terminate()
688+
proc.kill()
689689
proc.join(timeout=5)
690690
m._metrics_process = None
691691

692692

693+
def test_forget_metrics_process_in_child_removes_it_from_registry():
694+
import multiprocessing
695+
696+
import feast.metrics as m
697+
698+
proc = MagicMock()
699+
children = {proc}
700+
with (
701+
patch.object(multiprocessing.process, "_children", children),
702+
patch.object(m, "_metrics_process", proc),
703+
):
704+
m._forget_metrics_process_in_child()
705+
assert proc not in children
706+
707+
693708
class TestMetricsYamlConfig:
694709
"""Verify metrics config in feature_store.yaml is respected.
695710

0 commit comments

Comments
 (0)