Skip to content

fix(tests): ✅ Stop asserting joblib's dispatch timing - #174

Merged
SongshGeo merged 1 commit into
devfrom
fix/flaky-worker-pid-assertion
Aug 19, 2026
Merged

fix(tests): ✅ Stop asserting joblib's dispatch timing#174
SongshGeo merged 1 commit into
devfrom
fix/flaky-worker-pid-assertion

Conversation

@SongshGeo

Copy link
Copy Markdown
Collaborator

#173Tests 3.11 on macos-latest 的失败。是测试写错了,不是代码有问题。

失败

tests/core/test_experiment.py::TestNumProcessInsideHydra::test_repeats_span_multiple_processes FAILED
E   AssertionError: all repeats shared one process: {2078}
1 failed, 706 passed

原因

断言写的是 4 次重复要落在多于一个 worker PID 上:

assert len(pids) > 1, f"all repeats shared one process: {pids}"

但 PID 2078 不是父进程 —— 前一条断言 pids != {os.getpid()} 是过了的。也就是说并行分支完全正常工作、loky worker 确实起来了,只是 joblib 把 4 个任务都派给了同一个 worker。

joblib 按 worker 就绪情况派发任务,而这些测试任务极短,第一个 worker 完全可能在其他 worker 启动完成之前就把 4 个都做完。这是调度时序,不是这段代码承诺的行为,我不该断言它。

改法

真正区分两个分支的是父进程:串行分支在父进程里跑,loky 永远不在。所以改成断言重复没有在父进程里执行,测试名也改成它实际检查的内容(test_repeats_runs_in_worker_processes)。

没有削弱回归能力

#169 的 bug 放回去,测试立刻挂:

E   AssertionError: repeats ran in the parent, so the parallel branch was skipped: {18952}
E   assert 18952 not in {18952}

修复在位时连跑 10 次全绿,全量套件 707 passed,ruff / format 通过。

与其他 PR 的关系

合进 dev 后 #173 会自动带上,Tests 3.11 on macos-latest 应当转绿。

Tests 3.13 on windows-latest 仍会红 —— 那是 dev 上七个月的老问题(#171),与此无关。

`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 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d4df6f86-75d1-476c-9a06-91c61d78b38e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SongshGeo
SongshGeo merged commit f349d69 into dev Aug 19, 2026
9 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant