()
| 181 | |
| 182 | # create a background task before the ws connection established |
| 183 | async def background_task(): |
| 184 | try: |
| 185 | await ws_ready.wait() |
| 186 | assert ws is not None |
| 187 | |
| 188 | await ws.send("ping") |
| 189 | data = await ws.receive() |
| 190 | assert data == "pong" |
| 191 | finally: |
| 192 | ws_should_close.set() |
| 193 | |
| 194 | async def _handle_ws(websocket: WebSocket) -> None: |
| 195 | nonlocal ws |