Skip to content

Commit 35938a6

Browse files
committed
Adding test
1 parent ed18026 commit 35938a6

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/test_graphqlws_subscription.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,3 +899,41 @@ async def test_graphqlws_subscription_reconnecting_session(
899899
break
900900

901901
assert transport._connected is False
902+
903+
904+
@pytest.mark.asyncio
905+
@pytest.mark.parametrize("server", [server_countdown], indirect=True)
906+
@pytest.mark.parametrize("subscription_str", [countdown_subscription_str])
907+
async def test_graphqlws_subscription_no_server_protocol(server, subscription_str):
908+
"""The goal of this test is to verify that if the client requests only the
909+
graphqlws subprotocol AND the server is not returning its subprotocol
910+
in its header, then the client will assume that the protocol used is
911+
the graphqlws subprotocol (See PR #586).
912+
"""
913+
914+
from gql.transport.websockets import WebsocketsTransport
915+
916+
url = f"ws://{server.hostname}:{server.port}/graphql"
917+
print(f"url = {url}")
918+
919+
transport = WebsocketsTransport(
920+
url=url,
921+
subprotocols=[WebsocketsTransport.GRAPHQLWS_SUBPROTOCOL],
922+
keep_alive_timeout=3,
923+
)
924+
925+
client = Client(transport=transport)
926+
927+
count = 10
928+
subscription = gql(subscription_str.format(count=count))
929+
930+
async with client as session:
931+
async for result in session.subscribe(subscription):
932+
933+
number = result["number"]
934+
print(f"Number received: {number}")
935+
936+
assert number == count
937+
count -= 1
938+
939+
assert count == -1

0 commit comments

Comments
 (0)