From 1597625fad26baa4893a2c6c9aab738521097fff Mon Sep 17 00:00:00 2001 From: Joshua Villasenor Date: Tue, 6 Jun 2023 07:53:17 -0700 Subject: [PATCH] Update runner run function to be async. (#27048) --- .../matter_yamltests/runner.py | 6 ++---- scripts/tests/yaml/runner.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/py_matter_yamltests/matter_yamltests/runner.py b/scripts/py_matter_yamltests/matter_yamltests/runner.py index 9d560216321494..08de8d758e84fd 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/runner.py +++ b/scripts/py_matter_yamltests/matter_yamltests/runner.py @@ -133,7 +133,7 @@ async def execute(self, request): async def stop(self): return - def run(self, parser_builder_config: TestParserBuilderConfig, runner_config: TestRunnerConfig): + async def run(self, parser_builder_config: TestParserBuilderConfig, runner_config: TestRunnerConfig): if runner_config and runner_config.hooks: start = time.time() runner_config.hooks.start(len(parser_builder_config.tests)) @@ -143,9 +143,7 @@ def run(self, parser_builder_config: TestParserBuilderConfig, runner_config: Tes if not parser or not runner_config: continue - loop = asyncio.get_event_loop() - result = loop.run_until_complete( - self._run_with_timeout(parser, runner_config)) + result = await self._run_with_timeout(parser, runner_config) if isinstance(result, Exception): raise (result) elif not result: diff --git a/scripts/tests/yaml/runner.py b/scripts/tests/yaml/runner.py index 1c9aca681b3109..04f30401eb1b02 100755 --- a/scripts/tests/yaml/runner.py +++ b/scripts/tests/yaml/runner.py @@ -16,6 +16,7 @@ import relative_importer # isort: split # noqa: F401 +import asyncio import importlib import os import sys @@ -269,7 +270,8 @@ def parse(parser_group: ParserGroup): runner_config = None runner = TestRunner() - return runner.run(parser_group.builder_config, runner_config) + loop = asyncio.get_event_loop() + return loop.run_until_complete(runner.run(parser_group.builder_config, runner_config)) @runner_base.command() @@ -279,7 +281,8 @@ def dry_run(parser_group: ParserGroup): runner_config = TestRunnerConfig(hooks=TestRunnerLogger()) runner = TestRunner() - return runner.run(parser_group.builder_config, runner_config) + loop = asyncio.get_event_loop() + return loop.run_until_complete(runner.run(parser_group.builder_config, runner_config)) @runner_base.command() @@ -293,7 +296,8 @@ def run(parser_group: ParserGroup, adapter: str, stop_on_error: bool, stop_on_wa runner_config = TestRunnerConfig(adapter, parser_group.pseudo_clusters, runner_options, runner_hooks) runner = TestRunner() - return runner.run(parser_group.builder_config, runner_config) + loop = asyncio.get_event_loop() + return loop.run_until_complete(runner.run(parser_group.builder_config, runner_config)) @runner_base.command() @@ -316,7 +320,8 @@ def websocket(parser_group: ParserGroup, adapter: str, stop_on_error: bool, stop server_address, server_port, server_path, server_arguments, websocket_runner_hooks) runner = WebSocketRunner(websocket_runner_config) - return runner.run(parser_group.builder_config, runner_config) + loop = asyncio.get_event_loop() + return loop.run_until_complete(runner.run(parser_group.builder_config, runner_config)) @runner_base.command() @@ -331,7 +336,8 @@ def chip_repl(parser_group: ParserGroup, adapter: str, stop_on_error: bool, stop runner_config = TestRunnerConfig(adapter, parser_group.pseudo_clusters, runner_options, runner_hooks) runner = __import__(runner, fromlist=[None]).Runner(repl_storage_path, commission_on_network_dut) - return runner.run(parser_group.builder_config, runner_config) + loop = asyncio.get_event_loop() + return loop.run_until_complete(runner.run(parser_group.builder_config, runner_config)) @runner_base.command()