From 89afe1398a283db11d38c7fe41ab5058fb78e82b Mon Sep 17 00:00:00 2001 From: Carolina Lopes Date: Tue, 31 Oct 2023 21:47:09 +0000 Subject: [PATCH 1/4] Remove start and stop from run method --- scripts/py_matter_yamltests/matter_yamltests/runner.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/py_matter_yamltests/matter_yamltests/runner.py b/scripts/py_matter_yamltests/matter_yamltests/runner.py index a25183feb6a9a6..6a759d5c1bc335 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/runner.py +++ b/scripts/py_matter_yamltests/matter_yamltests/runner.py @@ -156,12 +156,10 @@ async def run(self, parser_builder_config: TestParserBuilderConfig, runner_confi async def _run_with_timeout(self, parser: TestParser, config: TestRunnerConfig): status = True try: - await self.start() status = await asyncio.wait_for(self._run(parser, config), parser.timeout) except (Exception, CancelledError) as exception: status = exception finally: - await self.stop() return status async def _run(self, parser: TestParser, config: TestRunnerConfig): From e7630fb3ea3690a0588dbea62d13a3007ec986e4 Mon Sep 17 00:00:00 2001 From: Carolina Lopes Date: Tue, 31 Oct 2023 21:47:37 +0000 Subject: [PATCH 2/4] Add property to check if runner is connected --- .../matter_yamltests/websocket_runner.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/py_matter_yamltests/matter_yamltests/websocket_runner.py b/scripts/py_matter_yamltests/matter_yamltests/websocket_runner.py index c90c50d15a177f..578f563132d199 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/websocket_runner.py +++ b/scripts/py_matter_yamltests/matter_yamltests/websocket_runner.py @@ -19,6 +19,8 @@ import websockets +from websockets.protocol import State + from .hooks import WebSocketRunnerHooks from .runner import TestRunner @@ -46,6 +48,13 @@ def __init__(self, config: WebSocketRunnerConfig): self._server_startup_command = self._make_server_startup_command( config.server_path, config.server_arguments, config.server_port) + @property + def is_connected(self) -> bool: + if self._client is None: + return False + + return self._client.state == State.OPEN + async def start(self): self._server = await self._start_server(self._server_startup_command) self._client = await self._start_client(self._server_connection_url) From c91c13868c87c71a02b09dd88eee2851edeae5d2 Mon Sep 17 00:00:00 2001 From: Carolina Lopes Date: Thu, 9 Nov 2023 16:07:08 +0000 Subject: [PATCH 3/4] Add auto_start_stop config variable --- scripts/py_matter_yamltests/matter_yamltests/runner.py | 10 +++++++++- .../matter_yamltests/websocket_runner.py | 4 +--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/py_matter_yamltests/matter_yamltests/runner.py b/scripts/py_matter_yamltests/matter_yamltests/runner.py index 6a759d5c1bc335..0d0e01556d69ce 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/runner.py +++ b/scripts/py_matter_yamltests/matter_yamltests/runner.py @@ -70,11 +70,15 @@ class TestRunnerConfig: hooks: A configurable set of hooks to be called at various steps while running. It may may allow the callers to gain insights about the current running state. + + auto_start_stop: Indicates wheter the run method should start and stop + the runner of if that will be handled outside of that method. """ adapter: TestAdapter = None pseudo_clusters: PseudoClusters = PseudoClusters([]) options: TestRunnerOptions = field(default_factory=TestRunnerOptions) hooks: TestRunnerHooks = TestRunnerHooks() + auto_start_stop: bool = True class TestRunnerBase(ABC): @@ -109,7 +113,7 @@ async def execute(self, request): pass @abstractmethod - def run(self, config: TestRunnerConfig) -> bool: + def run(self, parser_builder_config: TestParserBuilderConfig, runner_config: TestRunnerConfig) -> bool: """ This method runs a test suite. @@ -156,10 +160,14 @@ async def run(self, parser_builder_config: TestParserBuilderConfig, runner_confi async def _run_with_timeout(self, parser: TestParser, config: TestRunnerConfig): status = True try: + if config.auto_start_stop: + await self.start() status = await asyncio.wait_for(self._run(parser, config), parser.timeout) except (Exception, CancelledError) as exception: status = exception finally: + if config.auto_start_stop: + await self.stop() return status async def _run(self, parser: TestParser, config: TestRunnerConfig): diff --git a/scripts/py_matter_yamltests/matter_yamltests/websocket_runner.py b/scripts/py_matter_yamltests/matter_yamltests/websocket_runner.py index 578f563132d199..c63554ecf064b0 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/websocket_runner.py +++ b/scripts/py_matter_yamltests/matter_yamltests/websocket_runner.py @@ -19,8 +19,6 @@ import websockets -from websockets.protocol import State - from .hooks import WebSocketRunnerHooks from .runner import TestRunner @@ -53,7 +51,7 @@ def is_connected(self) -> bool: if self._client is None: return False - return self._client.state == State.OPEN + return self._client.state == websockets.protocol.State.OPEN async def start(self): self._server = await self._start_server(self._server_startup_command) From 37c1fe0595c9536d75a8c62cbdfd0c2fa603ae14 Mon Sep 17 00:00:00 2001 From: Carolina Lopes Date: Thu, 9 Nov 2023 20:31:32 +0000 Subject: [PATCH 4/4] Fix typo --- scripts/py_matter_yamltests/matter_yamltests/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/py_matter_yamltests/matter_yamltests/runner.py b/scripts/py_matter_yamltests/matter_yamltests/runner.py index 0d0e01556d69ce..541a261a43b4b2 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/runner.py +++ b/scripts/py_matter_yamltests/matter_yamltests/runner.py @@ -71,7 +71,7 @@ class TestRunnerConfig: running. It may may allow the callers to gain insights about the current running state. - auto_start_stop: Indicates wheter the run method should start and stop + auto_start_stop: Indicates whether the run method should start and stop the runner of if that will be handled outside of that method. """ adapter: TestAdapter = None