Skip to content

Commit 438aedc

Browse files
committed
Test parallel await
1 parent 3de6454 commit 438aedc

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/execution/test_executor.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,3 +866,46 @@ def resolve_field(self, parent_type, source, field_nodes, path):
866866
{"foo": "barbar"},
867867
None,
868868
)
869+
870+
@mark.asyncio
871+
async def resolve_fields_in_parallel():
872+
class Barrier(object):
873+
# Makes progress only if at least `count` callers are `wait()`ing.
874+
def __init__(self, count):
875+
self.ev = asyncio.Event()
876+
self.count = count
877+
878+
async def wait(self):
879+
self.count -= 1
880+
if self.count == 0:
881+
self.ev.set()
882+
883+
return await self.ev.wait()
884+
885+
barrier = Barrier(2)
886+
887+
async def f(*args):
888+
return await barrier.wait()
889+
890+
schema = GraphQLSchema(
891+
GraphQLObjectType(
892+
"Object",
893+
{
894+
"foo": GraphQLField(GraphQLBoolean, resolve=f),
895+
"bar": GraphQLField(GraphQLBoolean, resolve=f),
896+
}
897+
)
898+
)
899+
900+
query = '{foo, bar}'
901+
ast = parse(query)
902+
903+
res = await asyncio.wait_for(
904+
execute(schema, ast),
905+
1.0, # don't wait forever for the test to fail
906+
)
907+
908+
assert res == (
909+
{"foo": True, "bar": True},
910+
None,
911+
)

0 commit comments

Comments
 (0)