Skip to content

WebSocket handler on server side issue? #6980

Answered by Henddher
Henddher asked this question in Q&A
Discussion options

You must be logged in to vote

Here is the minimal test (hopefully clear enough)

I added strings to each assert to differentiate.

async def test_handler(event_loop, aiohttp_client):

    async def ws_handler(request):
        ws = aiohttp.web.WebSocketResponse()
        await ws.prepare(request)
        while True:
            await asyncio.sleep(2)
            await ws.send_json({"action": "wait"})

    app = aiohttp.web.Application()
    app.router.add_get("/ws", ws_handler)
    client = await aiohttp_client(app)
    try:
      async with client.ws_connect("/ws") as ws:
          assert False, "Before receive..."
          rawmsg = await ws.receive()
          assert (msg := ws_utils.tomsg(rawmsg))
    except Exception 

Replies: 2 comments 16 replies

Comment options

You must be logged in to vote
4 replies
@Henddher
Comment options

@Dreamsorcerer
Comment options

@Henddher
Comment options

@Dreamsorcerer
Comment options

Comment options

You must be logged in to vote
12 replies
@Dreamsorcerer
Comment options

@Henddher
Comment options

@Henddher
Comment options

@Dreamsorcerer
Comment options

@Henddher
Comment options

Answer selected by Henddher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants