Skip to content

Commit

Permalink
make graphql_ws test less timing-sensitive. (#2785)
Browse files Browse the repository at this point in the history
* make graphql_ws test less timing-sensitive.

* Mark a timing dependent test as flaky
  • Loading branch information
kristjanvalur authored May 31, 2023
1 parent b4c53b9 commit 79fdbd3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions tests/websockets/test_graphql_transport_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,9 @@ async def test_rejects_connection_params_not_unset(ws_raw: WebSocketClient):
ws.assert_reason("Invalid connection init payload")


# timings can sometimes fail currently. Until this test is rewritten when
# generator based subscriptions are implemented, mark it as flaky
@pytest.mark.flaky
async def test_subsciption_cancel_finalization_delay(ws: WebSocketClient):
# Test that when we cancel a subscription, the websocket isn't blocked
# while some complex finalization takes place.
Expand Down
16 changes: 10 additions & 6 deletions tests/websockets/test_graphql_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,17 @@ async def test_sends_keep_alive(aiohttp_app_client: HttpClient):
response = await ws.receive_json()
assert response["type"] == GQL_CONNECTION_ACK

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

response = await ws.receive_json()
assert response["type"] == GQL_CONNECTION_KEEP_ALIVE
# we can't be sure how many keep-alives exactly we
# get but they should be more than one.
keepalive_count = 0
while True:
response = await ws.receive_json()
if response["type"] == GQL_CONNECTION_KEEP_ALIVE:
keepalive_count += 1
else:
break
assert keepalive_count >= 1

response = await ws.receive_json()
assert response["type"] == GQL_DATA
assert response["id"] == "demo"
assert response["payload"]["data"] == {"echo": "Hi"}
Expand Down

0 comments on commit 79fdbd3

Please sign in to comment.