Skip to content

Commit b8dc402

Browse files
authored
Create async loop outside of benchmark (#145)
1 parent 6099c96 commit b8dc402

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tests/benchmarks/test_execution_async.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ async def resolve_user(obj, info):
3838

3939

4040
def test_execute_basic_async(benchmark):
41-
try:
42-
run = asyncio.run
43-
except AttributeError: # Python < 3.7
44-
loop = asyncio.get_event_loop()
45-
run = loop.run_until_complete # type: ignore
46-
result = benchmark(lambda: run(graphql(schema, "query { user { id, name }}")))
41+
# Note: we are creating the async loop outside of the benchmark code so that
42+
# the setup is not included in the benchmark timings
43+
loop = asyncio.events.new_event_loop()
44+
asyncio.events.set_event_loop(loop)
45+
result = benchmark(
46+
lambda: loop.run_until_complete(graphql(schema, "query { user { id, name }}"))
47+
)
48+
asyncio.events.set_event_loop(None)
49+
loop.close()
4750
assert not result.errors
4851
assert result.data == {
4952
"user": {

0 commit comments

Comments
 (0)