fix(tests): isolate BEADS bridge test from 3.11 writer-loop race#272
fix(tests): isolate BEADS bridge test from 3.11 writer-loop race#272
Conversation
…1 flake The background writer loop in BeadsBridge drains _dirty every 0.2 s. On CPython 3.11 the event loop schedules the writer task during the awaits inside the HTTP round-trip (HTTP processing + aiosqlite writes), so the loop fires and calls _dirty.clear() after mark_dirty() but before the test assertion, leaving an empty set. Fix: call bridge.stop() before the clear+action+assert block so the writer task is torn down and cannot race the assertion. The route still calls mark_dirty() normally; only the background consumer is absent for the duration of the assertion.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe test Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Review rate limit: 2/3 reviews remaining, refill in 20 minutes. Comment |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by grok-code-fast-1:optimized:free · 152,540 tokens |
Diagnosis
test_create_task_marks_project_dirtyasserts thatproject_id in bridge._dirtyimmediately after a POST that creates a task. TheBeadsBridgewriter loop runs every 0.2 s in the background. On CPython 3.11 the event loop schedules the writer task during theawaitpoints inside the ASGI HTTP round-trip (HTTP framing + aiosqlite writes). The writer fires, doespending = list(self._dirty); self._dirty.clear(), and empties the set before the test assertion runs — leaving_dirtyempty and the assertion failing. The same commit passes on 3.13 where timing differs.Fix
One line in the test: call
await bridge.stop()beforebridge._dirty.clear(). This tears down the background writer task so it cannot race the assertion.mark_dirty()is synchronous and still adds to_dirtynormally; the only thing missing is the consumer that would clear it.Verification
tests/projects/test_routes_beads.py::test_create_task_marks_project_dirty5× in a row on the local machine (Python 3.14): all green.tests/projects/test_routes_beads.py(7 tests): all 7 green.Summary by CodeRabbit