Skip to content

Commit f55f110

Browse files
committed
Got all tests fully working
1 parent 6daea21 commit f55f110

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

src/graphql_server/http/async_base_view.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ async def setup_connection_params(
145145
context: Context,
146146
root_value: Optional[RootValue],
147147
) -> None:
148-
if connection_params is None:
149-
return
150-
151148
if isinstance(context, dict):
152149
context["connection_params"] = connection_params
153150
elif hasattr(context, "connection_params"):

src/graphql_server/subscriptions/protocols/graphql_transport_ws/handlers.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,7 @@ async def run_operation(self, operation: Operation[Context, RootValue]) -> None:
296296
operation_name=operation.operation_name,
297297
)
298298

299-
# TODO: maybe change PreExecutionError to an exception that can be caught
300-
301299
if isinstance(result_source, ExecutionResult):
302-
# if isinstance(result_source, PreExecutionError):
303-
# assert result_source.errors
304-
# await operation.send_initial_errors(result_source.errors)
305-
# else:
306300
await operation.send_next(result_source)
307301
else:
308302
is_first_result = True

src/graphql_server/subscriptions/protocols/graphql_ws/handlers.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,27 @@ async def handle_async_results(
205205
from graphql_server.runtime import process_errors
206206

207207
processed_errors = process_errors(e.errors)
208+
# for error in e.errors:
209+
error = e.errors[0]
208210
await self.send_message(
209211
ErrorMessage(
210212
type="error",
211213
id=operation_id,
212-
payload={"message": str(e)},
214+
payload=error.formatted,
213215
)
214216
)
215217
except asyncio.CancelledError:
216218
await self.send_message(CompleteMessage(type="complete", id=operation_id))
219+
except Exception as e:
220+
with suppress(Exception):
221+
await self.send_message(
222+
ErrorMessage(
223+
type="error",
224+
id=operation_id,
225+
payload={"message": str(e)},
226+
)
227+
)
228+
raise
217229

218230
async def cleanup_operation(self, operation_id: str) -> None:
219231
if operation_id in self.subscriptions:

src/tests/websockets/test_graphql_transport_ws.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,14 +1095,14 @@ async def test_error_handler_for_timeout(http_client: HttpClient):
10951095
"""Test that the error handler is called when the timeout
10961096
task encounters an error.
10971097
"""
1098-
with contextlib.suppress(ImportError):
1099-
from tests.http.clients.channels import ChannelsHttpClient
1098+
# with contextlib.suppress(ImportError):
1099+
# from tests.http.clients.channels import ChannelsHttpClient
11001100

1101-
if isinstance(http_client, ChannelsHttpClient):
1102-
pytest.skip("Can't patch on_init for this client")
1101+
# if isinstance(http_client, ChannelsHttpClient):
1102+
# pytest.skip("Can't patch on_init for this client")
11031103

1104-
if not AsyncMock:
1105-
pytest.skip("Don't have AsyncMock")
1104+
# if not AsyncMock:
1105+
# pytest.skip("Don't have AsyncMock")
11061106

11071107
ws = ws_raw
11081108
handler = None
@@ -1210,11 +1210,11 @@ async def test_unexpected_client_disconnects_are_gracefully_handled(
12101210
"payload": {"query": 'subscription { infinity(message: "Hi") }'},
12111211
}
12121212
)
1213-
await ws.receive(timeout=2)
1213+
await ws.receive(timeout=1)
12141214
assert Subscription.active_infinity_subscriptions == 1
12151215

12161216
await ws.close()
1217-
await asyncio.sleep(1)
1217+
await asyncio.sleep(0.5)
12181218

12191219
assert not process_errors.called
12201220
assert Subscription.active_infinity_subscriptions == 0

src/tests/websockets/test_graphql_ws.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ErrorMessage,
2222
StartMessage,
2323
)
24+
from tests.views.schema import Subscription
2425

2526
if TYPE_CHECKING:
2627
from tests.http.clients.base import HttpClient, WebSocketClient
@@ -48,7 +49,7 @@ async def ws(ws_raw: WebSocketClient) -> AsyncGenerator[WebSocketClient, None]:
4849

4950
await ws.send_legacy_message({"type": "connection_terminate"})
5051
# make sure the WebSocket is disconnected now
51-
await ws.receive(timeout=2) # receive close
52+
await ws.receive(timeout=1) # receive close
5253
assert ws.closed
5354

5455

@@ -400,7 +401,7 @@ async def test_subscription_errors(ws: WebSocketClient):
400401
data_message: DataMessage = await ws.receive_json()
401402
assert data_message["type"] == "data"
402403
assert data_message["id"] == "demo"
403-
assert data_message["payload"]["data"] is None
404+
assert data_message["payload"]["data"]["error"] is None
404405

405406
assert "errors" in data_message["payload"]
406407
assert data_message["payload"]["errors"] is not None
@@ -653,7 +654,7 @@ async def test_resolving_enums(ws: WebSocketClient):
653654
assert complete_message["id"] == "demo"
654655

655656

656-
@pytest.mark.xfail(reason="flaky test")
657+
# @pytest.mark.xfail(reason="flaky test")
657658
async def test_task_cancellation_separation(http_client: HttpClient):
658659
# Note Python 3.7 does not support Task.get_name/get_coro so we have to use
659660
# repr(Task) to check whether expected tasks are running.
@@ -862,7 +863,7 @@ async def test_unexpected_client_disconnects_are_gracefully_handled(
862863
assert Subscription.active_infinity_subscriptions == 1
863864

864865
await ws.close()
865-
await asyncio.sleep(1)
866+
await asyncio.sleep(0.5)
866867

867868
assert not process_errors.called
868869
assert Subscription.active_infinity_subscriptions == 0

0 commit comments

Comments
 (0)