From d42a60ce57d016f98cd8c2709f72a891b27a5064 Mon Sep 17 00:00:00 2001 From: SongshGeo Date: Tue, 18 Aug 2026 23:30:47 +0200 Subject: [PATCH] fix(tests): :white_check_mark: Stop asserting joblib's dispatch timing `test_repeats_span_multiple_processes` asserted the four repeats landed on more than one worker PID. That is joblib's dispatch timing, not a promise this code makes: the runs are short enough that one worker can take all four before the others have finished starting, which is what happened on the macOS 3.11 runner: AssertionError: all repeats shared one process: {2078} PID 2078 was not the parent, so the parallel branch had worked exactly as intended -- the assertion was simply testing something the implementation never guaranteed. What actually separates the two branches is the parent process: the sequential branch runs there and loky never does. The test now asserts the repeats did not run in the parent, and is renamed for what it checks. This does not weaken the regression. Restoring the #169 bug still fails it: AssertionError: repeats ran in the parent, so the parallel branch was skipped: {18952} Ran 10 consecutive times against the fix with no flake; full suite 707 passed. Co-Authored-By: Claude Opus 5 --- tests/core/test_experiment.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/core/test_experiment.py b/tests/core/test_experiment.py index f665967..17a6e23 100644 --- a/tests/core/test_experiment.py +++ b/tests/core/test_experiment.py @@ -178,8 +178,8 @@ def test_sequential_path_still_records_results(self, pid_config): assert len(summary) == 3, f"expected 3 recorded runs, got {len(summary)}" assert set(summary["worker_pid"]) == {os.getpid()} - def test_repeats_span_multiple_processes(self, pid_config, tmp_path): - """Repeats run in worker processes, not all in the parent.""" + def test_repeats_runs_in_worker_processes(self, pid_config, tmp_path): + """Repeats run in worker processes rather than in the parent.""" exp = Experiment.new(PidReportingMod, pid_config) with _inside_hydra_job( "hydra._internal.core_plugins.basic_launcher.BasicLauncher", @@ -190,9 +190,15 @@ def test_repeats_span_multiple_processes(self, pid_config, tmp_path): summary = exp.summary() assert len(summary) == 4, f"expected 4 recorded runs, got {len(summary)}" + # Whether the repeats land on one worker or four is joblib's dispatch + # timing, not a promise this code makes: these runs are short enough + # that one worker can take all four before the others have started. + # What distinguishes the two branches is the parent process, and loky + # never executes in it. pids = set(summary["worker_pid"]) - assert pids != {os.getpid()}, "every repeat ran in the parent process" - assert len(pids) > 1, f"all repeats shared one process: {pids}" + assert os.getpid() not in pids, ( + f"repeats ran in the parent, so the parallel branch was skipped: {pids}" + ) def test_yields_to_a_real_parallel_launcher(self, pid_config, tmp_path): """A launcher plugin already parallelises, so abses must not nest."""