Commit 0305b1a
Fix sse-starlette event-loop binding in streaming tests (#22)
Root cause:
sse_starlette.sse.AppStatus.should_exit_event is a class-level
anyio.Event lazily created on first SSE response. It binds to the
asyncio event loop that is running at that moment. pytest-asyncio
(>=0.21, function-scoped loop default in 1.x) creates a fresh event
loop per async test, so the second SSE test inherits an Event bound
to a now-closed loop and the SSE response raises:
RuntimeError: <asyncio.locks.Event ...> is bound to a different event loop
This made 5 streaming tests fail on main:
- test_stream_concatenated_content_matches_engine_decode
- test_stream_finish_reason_length_on_max_tokens
- test_stream_returns_done_sentinel_at_end
- test_stream_each_chunk_has_required_openai_fields
- test_stream_completion_id_consistent_across_chunks
Fix:
Add an autouse fixture in tests/inference_engine/server/conftest.py
that resets AppStatus.should_exit_event to None before and after
every test in this package. Production code is unaffected — uvicorn
stays on a single loop for the lifetime of the process so the lazy
init runs exactly once there.
Result:
tests/inference_engine/server/test_app_streaming.py: 11 passed
tests/inference_engine/server/ (full suite): 215 passed
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>1 parent 9d2c8d6 commit 0305b1a
1 file changed
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
33 | 78 | | |
34 | 79 | | |
35 | 80 | | |
| |||
0 commit comments