Commit 6baffde
committed
fix: resolve test hang with websockets 14+
The test suite hangs after upgrading websockets from 13.x to 14.x/15.x
because websockets 14.0 switched to a new asyncio implementation by default.
Changes:
1. In TestServer.serve(): Replace deprecated asyncio.get_event_loop()
pattern with asyncio.create_task() which is the modern way to create
tasks when already inside an async context.
2. In serve_in_thread(): Instead of relying on server.run() which uses
asyncio.run(), explicitly create a new event loop in the background
thread with asyncio.new_event_loop() and asyncio.set_event_loop().
3. Remove loop="asyncio" from Config() since we now manage the event
loop manually.
This approach is compatible with uvicorn 0.36+ (which removed the
deprecated setup_event_loop() method) and works with websockets 14+.
Fixes #37081 parent def4778 commit 6baffde
1 file changed
+12
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
238 | | - | |
239 | 238 | | |
240 | | - | |
241 | | - | |
| 239 | + | |
| 240 | + | |
242 | 241 | | |
243 | 242 | | |
244 | 243 | | |
| |||
269 | 268 | | |
270 | 269 | | |
271 | 270 | | |
272 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
273 | 280 | | |
274 | 281 | | |
275 | 282 | | |
| |||
282 | 289 | | |
283 | 290 | | |
284 | 291 | | |
285 | | - | |
| 292 | + | |
286 | 293 | | |
287 | 294 | | |
0 commit comments