Skip to content

Commit

Permalink
Remove faulty test
Browse files Browse the repository at this point in the history
Ping/Pong is automatically handled by aiohttp by default. So this test
would always pass but never test what it was supposed to test.
Technically we should handle and test for the "ERROR" message type. But
since that's an unrelated change, I'll do that in a separate PR.
  • Loading branch information
DoctorJohn committed Sep 18, 2024
1 parent 214cfe0 commit 9984916
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ async def handle_request(self) -> web.StreamResponse:
elif ws_message.type == http.WSMsgType.BINARY:
error_message = "WebSocket message type must be text"
await self.handle_invalid_message(error_message)
break
finally:
await self.shutdown()

Expand Down
1 change: 0 additions & 1 deletion strawberry/aiohttp/handlers/graphql_ws_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ async def handle_request(self) -> Any:
await self.close(
code=1002, reason="WebSocket message type must be text"
)
break
finally:
if self.keep_alive_task:
self.keep_alive_task.cancel()
Expand Down
43 changes: 0 additions & 43 deletions tests/aiohttp/test_websockets.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
from __future__ import annotations

import pytest
from typing import TYPE_CHECKING, Awaitable, Callable

from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL, GRAPHQL_WS_PROTOCOL
from strawberry.subscriptions.protocols.graphql_transport_ws.types import (
ConnectionAckMessage,
ConnectionInitMessage,
)
from strawberry.subscriptions.protocols.graphql_ws import (
GQL_CONNECTION_ACK,
GQL_CONNECTION_INIT,
)

if TYPE_CHECKING:
from aiohttp.test_utils import TestClient
Expand Down Expand Up @@ -117,37 +108,3 @@ async def test_clients_can_prefer_protocols(
"/graphql", protocols=[GRAPHQL_WS_PROTOCOL, GRAPHQL_TRANSPORT_WS_PROTOCOL]
) as ws:
assert ws.protocol == GRAPHQL_WS_PROTOCOL


@pytest.mark.parametrize(
("subprotocol", "init_message", "ack_message_type"),
[
(
GRAPHQL_WS_PROTOCOL,
ConnectionInitMessage().as_dict(),
ConnectionAckMessage.type,
),
(
GRAPHQL_TRANSPORT_WS_PROTOCOL,
{"type": GQL_CONNECTION_INIT},
GQL_CONNECTION_ACK,
),
],
)
async def test_non_text_or_binary_ws_messages_are_still_allowed(
aiohttp_client: Callable[..., Awaitable[TestClient]], subprotocol, init_message, ack_message_type
) -> None:
from .app import create_app

app = create_app()
aiohttp_app_client = await aiohttp_client(app)

async with aiohttp_app_client.ws_connect("/graphql", protocols=[subprotocol]) as ws:
await ws.ping()

await ws.send_json(init_message)

response = await ws.receive_json()
assert response["type"] == ack_message_type

await ws.close()

0 comments on commit 9984916

Please sign in to comment.