Replies: 2 comments 17 replies
-
Hi @wholmen 👋 Is there a reason why you want to run your client connection into a task? IMO, it would be way easier for debugging/reasoning to just run it in the main context: @pytest.mark.asyncio
async def test_add_lab_test(labtest_client_async: httpx.AsyncClient):
sub_queue: asyncio.Queue = asyncio.Queue()
async with httpx_ws.aconnect_ws("/labtests/ws", labtest_client_async) as ws:
message = await ws.receive_json()
await sub_queue.put(message)
await asyncio.sleep(SHORT_WAIT)
message_labtest1 = await sub_queue.get()
print(f"{message_labtest1=}") |
Beta Was this translation helpful? Give feedback.
5 replies
-
Beta Was this translation helpful? Give feedback.
12 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, reposting the issue to this github.
I am struggling with httpx-ws. It works when the server-side websocket connection is closed, but my implementations are based on websockets that are open until the client breaks them. Could you help me adjusting the code to make the implementation work?
Websocket implementation
Test implementation
The websocket works fine when I use e.g. Postman to connect to the websocket. It seems httpx_ws is unable to close the connection even though I say
task.cancel()
. That makes the test run until I force quit.It seems like the problem being related to
asyncio.create_task
. If I don't wait for the "add labtest event" in server, I manage to get the message sent to me. So it seems like the connection struggles to run as a background task. Maybe this is completely out of scope. I am open to ideas on how to do this kind of integration testing.I know the code is not self-contained. If it's hard to understand, I can make a simpler self-contained example
Beta Was this translation helpful? Give feedback.
All reactions