It seems that certain WebSocket patterns are tricky to write proper tests for.
For instance, consider an emitter that mostly streams updates to the client:
import asyncio
import falcon.asgi
import falcon.testing
class Channel:
async def on_websocket(self, req, ws):
await ws.accept()
while True:
await asyncio.sleep(1)
await ws.send_text('Hello')
@falcon.runs_sync
async def test_ws():
async with falcon.testing.ASGIConductor(falcon.asgi.App()) as ac:
ac.app.add_route('/', Channel())
async with ac.websocket('/') as ws:
await ws.wait_ready(timeout=3.0)
The above test works just fine.
However, let's say we want to simulate the scenario where no messages are made available for a while (the ws.send_text part is commented out):
import asyncio
import falcon.asgi
import falcon.testing
class Channel:
async def on_websocket(self, req, ws):
await ws.accept()
while True:
await asyncio.sleep(1)
# await ws.send_text('Hello')
@falcon.runs_sync
async def test_ws():
async with falcon.testing.ASGIConductor(falcon.asgi.App()) as ac:
ac.app.add_route('/', Channel())
async with ac.websocket('/') as ws:
await ws.wait_ready(timeout=3.0)
Pytest now hangs forever, the timeout parameter has no effect.
It seems that certain WebSocket patterns are tricky to write proper tests for.
For instance, consider an emitter that mostly streams updates to the client:
The above test works just fine.
However, let's say we want to simulate the scenario where no messages are made available for a while (the
ws.send_textpart is commented out):Pytest now hangs forever, the timeout parameter has no effect.