add graphql websocket subsciption tests#768
Conversation
a0653ed to
8738722
Compare
de961c1 to
3503725
Compare
There was a problem hiding this comment.
LGTM, one question (see comment).
This pushes code coverage in the right direction 👍:
There are still a few gaps:
- Would be good to cover error handling, e.g, GraphQL validation errors.
- Would be good to cover more of the websocket subprocotocol (though note that we will change subprotocol soon)
- Would be good to cover connection termination (as this is something we've had issues with).
| response = json.loads(await ws.read_message()) | ||
|
|
||
| assert response == { | ||
| 'id': sub_id, | ||
| 'type': 'data', | ||
| 'payload': { | ||
| 'data': { | ||
| 'workflows': [ | ||
| { | ||
| 'id': '~me/foo', | ||
| 'status': 'stopped' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Would be good to test that the subscription can yield more than one result, i.e:
for _ in range(3):
assert json.loads(await ws.read_message()) == { ...
# poke UIS subscriptions as though something changed to make them yield again
await do_something()Not sure what do_something is though?
Yes, this is a work in process, I'll keep expanding the tests here (hopefully until 85% project coverage at min) |
3503725 to
e1c4e1f
Compare
1627744 to
5710e81
Compare
|
83% project coverage 🥇 Ping me when you want a review. |
Just need to bump up the websocket/subscription side of things first. |
aa4cf1c to
a212c89
Compare
|
@oliver-sanders - I think this will do for now, there's some more that could be done with the subscription handler.. But we might as well get this in as a first step for people to build on. |
|
(shifting this onto the 1.9.0 milestone as there are functional code changes) |
| # test against same query different method | ||
| post_response = await gql_query(*('cylc', 'graphql'), query=query) | ||
| assert get_response.body == post_response.body |
There was a problem hiding this comment.
Is this right?
Isn't GET for queries and POST for mutations?
There was a problem hiding this comment.
Quite right, a little more work to do here, it's not being caught by the thing that should catch it.
There was a problem hiding this comment.
So it appears that the only restriction is mutations have to be POST, it's the same with Django:
https://github.com/graphql-python/graphene-django/blob/f02ea337a23df06d166d463d6f92cb7505fbb435/graphene_django/views.py#L322-L337
I do test this..
# try a mutation with GET method
response = await gql_query(
*('cylc', 'graphql'),
headers={'Content-Type': 'application/x-www-form-urlencoded'},
query='''
mutation {
stop(workflows: ["*"]) {
result
}
}
''',
method='GET',
raise_error=False
)
# Should be rejected for incorrect method.
assert response.code == 405
assert response.reason == 'Method Not Allowed'
So GET or POST for queries, only POST for mutations.. The POST just means we package the query into the body instead of URL..
So, "nothing to see here.."
FYI: We'll be looking to release 1.9.0 shortly once the new Cylc Review is in, would be great to merge this pre-release. |
a212c89 to
8d30303
Compare
@oliver-sanders - This is ready to go.. (was a while ago but I thought the whole POST query would be more narly, turned out it was the norm amongst framework implementations of graphql) ( Maybe #797 and others ... But this PR does what it says and 100% on this patch... So follow-ons to get coverage up. |
|
(project coverage is just a target, you don't have to hit that number in this PR!) |
Yeah, there is one thing annoying me though.. The async gens are not being served: (which doesn't seem to make sense, because how can the stuff at the beginning of I think I need to try push the subscriptions a little further.. Like you mentioned: So will try get that covered at least |
8d30303 to
f579490
Compare
|
Not sure what's with coverage, that block is hit: then forcing an assert error shows it in the stdout: 🤷 |
|
(re-running CI on fresh merge to see if coverage reports change) |
|
(Codecov sometimes jitters, I think test re-runs can cause it, a fresh run fixes it) |


Adds an integration test for testing the graphql subscriptions via websocket connection.
Check List
CONTRIBUTING.mdand added my name as a Code Contributor.setup.cfg(andconda-environment.ymlif present).?.?.xbranch.