Skip to content

Commit

Permalink
Test parallel await
Browse files Browse the repository at this point in the history
  • Loading branch information
mawa committed Sep 21, 2018
1 parent 3de6454 commit 438aedc
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/execution/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,3 +866,46 @@ def resolve_field(self, parent_type, source, field_nodes, path):
{"foo": "barbar"},
None,
)

@mark.asyncio
async def resolve_fields_in_parallel():
class Barrier(object):
# Makes progress only if at least `count` callers are `wait()`ing.
def __init__(self, count):
self.ev = asyncio.Event()
self.count = count

async def wait(self):
self.count -= 1
if self.count == 0:
self.ev.set()

return await self.ev.wait()

barrier = Barrier(2)

async def f(*args):
return await barrier.wait()

schema = GraphQLSchema(
GraphQLObjectType(
"Object",
{
"foo": GraphQLField(GraphQLBoolean, resolve=f),
"bar": GraphQLField(GraphQLBoolean, resolve=f),
}
)
)

query = '{foo, bar}'
ast = parse(query)

res = await asyncio.wait_for(
execute(schema, ast),
1.0, # don't wait forever for the test to fail
)

assert res == (
{"foo": True, "bar": True},
None,
)

0 comments on commit 438aedc

Please sign in to comment.