fix: resolve test hang with websockets 14+ #3720
Closed
+12
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3708
The test suite hangs indefinitely when upgrading
websocketsfrom 13.x to 14.x or 15.x. This is because websockets 14.0 switched to a new asyncio implementation by default, which has different behavior around event loop handling.Root Cause
The issue stems from how the
TestServermanages event loops when running in a background thread:TestServer.serve(): The deprecatedasyncio.get_event_loop()+loop.create_task()pattern doesn't work correctly with websockets 14+'s new asyncio handlingserve_in_thread(): Theserver.run()method relies onasyncio.run()which doesn't play well with the threaded setup when websockets is involvedChanges
TestServer.serve(): Replace deprecatedasyncio.get_event_loop()pattern withasyncio.create_task()which is the modern way to create tasks when already inside an async context.serve_in_thread(): Instead of relying onserver.run()which usesasyncio.run(), explicitly create a new event loop in the background thread withasyncio.new_event_loop()andasyncio.set_event_loop().serverfixture: Removeloop="asyncio"fromConfig()since we now manage the event loop manually, avoiding conflicts with websockets' asyncio implementation.Testing
Tested locally with websockets 15.0.1 - all 43 integration tests pass without hanging.