test: simplify registry import reload coverage#3077
Conversation
|
@codex review |
|
✅ No security or compliance issues detected. Reviewed everything up to 076a714. Security Overview
Detected Code Changes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 076a7144fc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| def reload_module(*, signal_started: bool = False) -> ModuleType: | ||
| if signal_started: | ||
| second_call_started.set() |
There was a problem hiding this comment.
Wait until the second reload actually contends
The event is signaled before the worker calls import_and_reload, so it does not prove the second thread has attempted to acquire the reload lock. If that worker is descheduled after second_call_started.set()—for example on a loaded CI runner—the 100 ms check can expire, the first reload is released, and the second then runs after it finishes; max_active_reloads remains 1 even with _import_reload_lock removed, allowing the regression this test is intended to catch to pass.
Useful? React with 👍 / 👎.
Summary
tracecat_registrymodulesimport_and_reloadWhy
The deleted
test_import_reload_no_race_with_lockdid not actually prove that the process-wide lock was effective. It still passed when_import_reload_lockwas replaced withcontextlib.nullcontext(), so removing the lock would not have caused the regression test to fail.The file also contained:
tracecat_registryentries insys.modules, adding broad state and timing dependence to a unit testRegistry sync is now subprocess-isolated, but
import_and_reloadis still used by local-repository and recovery paths. This PR therefore keeps the relevant contracts and tests them directly:importlib.reloadsimultaneously.The new serialization test fails when the lock is disabled, unlike the old stress test. In the local timing run, the removed tests accounted for about 4.8 seconds of test-call time; the new concurrency test completes in about 0.1 seconds.
Validation
uv run pytest tests/unit/test_registry_repository.py -q --durations=10uv run ruff check tests/unit/test_registry_repository.pyuv run ruff format --check tests/unit/test_registry_repository.pyuv run basedpyright tests/unit/test_registry_repository.py_import_reload_lockis disabledSummary by cubic
Simplifies registry import/reload tests by removing the flaky race harness and adding fast, focused tests that verify reload failure handling and process-wide serialization.
tests/unit/test_registry_import_race.pyand its flaky race/stress cases againsttracecat_registry.import_and_reload:import_module).importlib.reloadnever runs in parallel.Written for commit 076a714. Summary will update on new commits.