Skip to content

Create async loop outside of benchmark #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions tests/benchmarks/test_execution_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ async def resolve_user(obj, info):


def test_execute_basic_async(benchmark):
try:
run = asyncio.run
except AttributeError: # Python < 3.7
loop = asyncio.get_event_loop()
run = loop.run_until_complete # type: ignore
result = benchmark(lambda: run(graphql(schema, "query { user { id, name }}")))
# Note: we are creating the async loop outside of the benchmark code so that
# the setup is not included in the benchmark timings
loop = asyncio.events.new_event_loop()
asyncio.events.set_event_loop(loop)
result = benchmark(
lambda: loop.run_until_complete(graphql(schema, "query { user { id, name }}"))
)
asyncio.events.set_event_loop(None)
loop.close()
assert not result.errors
assert result.data == {
"user": {
Expand Down