Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client unable to handle websocket connection rejections #54

Open
hollandjake opened this issue Jun 11, 2022 · 2 comments · May be fixed by #55
Open

Client unable to handle websocket connection rejections #54

hollandjake opened this issue Jun 11, 2022 · 2 comments · May be fixed by #55

Comments

@hollandjake
Copy link

In the scenario where a websocket connection is closed before being accepted by the server, the WebSocketSession currently throws an AssertionError due to the received message not being type "websocket.accept" (see assertion)

If a connection request is cancelled before being accepted it should raise the message in someway so tests can process the response.

This should also apply to any message being received first that isn't an accept type since any of these would be a failure of the websocket protocol

@hollandjake
Copy link
Author

Example test to show failure

@pytest.mark.asyncio
async def test():
  app = FastAPI()
  @app.websocket("/ws")
  async def ws(websocket: WebSocket):
    await websocket.close() # Reject the connection

  async with TestClient(app) as client:
    async with client.websocket_connect("/ws") as ws:
      pass

@hollandjake hollandjake linked a pull request Jun 12, 2022 that will close this issue
@ThomasDsantos
Copy link

ThomasDsantos commented Jun 29, 2023

Hello all ! Any update on this issue (and merge request linked) ? Will be useful for me too 😄

Merge request LGTM but can't do anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants