Skip to content

Commit

Permalink
Remove tests for long contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Oct 13, 2024
1 parent 1be5a06 commit c074e09
Showing 1 changed file with 2 additions and 72 deletions.
74 changes: 2 additions & 72 deletions tests/websockets/test_graphql_transport_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,12 +1071,7 @@ async def test_long_validation_concurrent_query(ws: WebSocketClient):
# we expect the second query to arrive first, because the
# first query is stuck in validation
response = await ws.receive_json()
assert (
response
== NextMessage(
id="sub2", payload={"data": {"conditionalFail": "Hey"}}
).as_dict()
)
assert_next(response, "sub2", {"conditionalFail": "Hey"})


async def test_long_validation_concurrent_subscription(ws: WebSocketClient):
Expand Down Expand Up @@ -1104,72 +1099,7 @@ async def test_long_validation_concurrent_subscription(ws: WebSocketClient):
# we expect the second query to arrive first, because the
# first operation is stuck in validation
response = await ws.receive_json()
assert (
response
== NextMessage(
id="sub2", payload={"data": {"conditionalFail": "Hey"}}
).as_dict()
)


async def test_long_custom_context(
ws: WebSocketClient, http_client_class: Type[HttpClient]
):
"""
Test that the websocket is not blocked evaluating the context
"""
if http_client_class in (FastAPIHttpClient, StarliteHttpClient, LitestarHttpClient):
pytest.skip("Client evaluates the context only once per connection")

counter = 0

async def slow_get_context(ctxt):
nonlocal counter
old = counter
counter += 1
if old == 0:
await asyncio.sleep(0.1)
ctxt["custom_value"] = "slow"
else:
ctxt["custom_value"] = "fast"
return ctxt

with patch("tests.http.context.get_context_async_inner", slow_get_context):
await ws.send_json(
SubscribeMessage(
id="sub1",
payload=SubscribeMessagePayload(query="query { valueFromContext }"),
).as_dict()
)

await ws.send_json(
SubscribeMessage(
id="sub2",
payload=SubscribeMessagePayload(
query="query { valueFromContext }",
),
).as_dict()
)

# we expect the second query to arrive first, because the
# first operation is stuck getting context
response = await ws.receive_json()
assert (
response
== NextMessage(
id="sub2", payload={"data": {"valueFromContext": "fast"}}
).as_dict()
)

response = await ws.receive_json()
if response == CompleteMessage(id="sub2").as_dict():
response = await ws.receive_json() # ignore the complete message
assert (
response
== NextMessage(
id="sub1", payload={"data": {"valueFromContext": "slow"}}
).as_dict()
)
assert_next(response, "sub2", {"conditionalFail": "Hey"})


async def test_task_error_handler(ws: WebSocketClient):
Expand Down

0 comments on commit c074e09

Please sign in to comment.