Skip to content

Commit f613ef9

Browse files
committed
Use colcon's new_event_loop for async benchmarking
1 parent d0b03c6 commit f613ef9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

test/conftest.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Copyright 2023 Open Source Robotics Foundation, Inc.
22
# Licensed under the Apache License, Version 2.0
33

4+
import asyncio
45
import logging
56
import os
67
import unittest.mock
78
import warnings
89

910
from colcon_core.package_descriptor import PackageDescriptor
11+
from colcon_core.subprocess import new_event_loop
1012
from colcon_python_project.hook_caller_decorator.setuptools \
1113
import SetuptoolsHookCallerDecoratorExtension
1214
import pytest
@@ -15,6 +17,16 @@
1517
from .backend_fixtures import MOCK_BACKENDS
1618

1719

20+
@pytest.fixture
21+
def colcon_event_loop():
22+
loop = new_event_loop()
23+
asyncio.set_event_loop(loop)
24+
yield loop
25+
loop.run_until_complete(loop.shutdown_asyncgens())
26+
asyncio.set_event_loop(None)
27+
loop.close()
28+
29+
1830
@pytest.fixture(autouse=True)
1931
def better_benchmarking(request):
2032
if 'benchmark' not in request.fixturenames:
@@ -55,10 +67,11 @@ def override_extensions(group_name, *args, **kwargs):
5567

5668

5769
@pytest.fixture
58-
def bench(benchmark, event_loop):
70+
def bench(benchmark, colcon_event_loop):
5971
def res(target, *args, **kwargs):
6072
def dut():
61-
return event_loop.run_until_complete(target(*args, **kwargs))
73+
return colcon_event_loop.run_until_complete(
74+
target(*args, **kwargs))
6275
return benchmark(dut)
6376
return res
6477

test/spell_check.words

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ament
22
apache
3+
asyncgens
34
asyncio
45
augmentor
56
autouse

0 commit comments

Comments
 (0)