Skip to content

Commit 6b6f003

Browse files
committed
graphql subscription test added
1 parent 013d3ed commit 6b6f003

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/integration/network/test_graphql.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@
1616

1717
"""Test the top-level (root) GraphQL queries."""
1818

19+
from contextlib import suppress
1920
import pytest
2021
from typing import TYPE_CHECKING
2122

23+
from graphql import parse, MiddlewareManager
24+
2225
from cylc.flow.id import Tokens
2326
from cylc.flow.network.client import WorkflowRuntimeClient
27+
from cylc.flow.network.schema import schema, SUB_RESOLVER_MAPPING
28+
from cylc.flow.network.graphql import (
29+
CylcExecutionContext,
30+
IgnoreFieldMiddleware,
31+
instantiate_middleware,
32+
)
33+
from cylc.flow.network.graphql_subscribe import subscribe
2434

2535
if TYPE_CHECKING:
2636
from cylc.flow.scheduler import Scheduler
@@ -362,3 +372,40 @@ async def test_jobs(harness):
362372
assert ret == {
363373
'job': {'id': f'{j_id}'}
364374
}
375+
376+
377+
@pytest.mark.asyncio(loop_scope="module")
378+
async def test_subscription(harness):
379+
"""Test the GraphQL subscription infrastructure.
380+
381+
(currently only used at UIS)
382+
"""
383+
schd, client, w_tokens = harness
384+
385+
request_string = 'subscription { workflows (stripNull: true) { id } }'
386+
kwargs = {
387+
"variable_values": {},
388+
"operation_name": None,
389+
"context_value": {
390+
'op_id': 1,
391+
'resolvers': schd.server.resolvers,
392+
'meta': {},
393+
},
394+
"subscribe_resolver_map": SUB_RESOLVER_MAPPING,
395+
"middleware": MiddlewareManager(
396+
instantiate_middleware(
397+
[IgnoreFieldMiddleware]
398+
)
399+
),
400+
"execution_context_class": CylcExecutionContext,
401+
}
402+
document = parse(request_string)
403+
result = await subscribe(
404+
schema.graphql_schema,
405+
document,
406+
**kwargs
407+
)
408+
with suppress(GeneratorExit):
409+
async for item in result:
410+
assert item.data['workflows'][0]['id'] == w_tokens.id
411+
await result.aclose()

0 commit comments

Comments
 (0)