Skip to content

Commit

Permalink
Remove start and stop from run (#30396)
Browse files Browse the repository at this point in the history
* Remove start and stop from run method

* Add property to check if runner is connected

* Add auto_start_stop config variable

* Fix typo
  • Loading branch information
ccruzagralopes authored and pull[bot] committed Nov 17, 2023
1 parent 7fcf9ca commit 4675443
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions scripts/py_matter_yamltests/matter_yamltests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 whether 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):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -156,12 +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:
await self.start()
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:
await self.stop()
if config.auto_start_stop:
await self.stop()
return status

async def _run(self, parser: TestParser, config: TestRunnerConfig):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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 == websockets.protocol.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)
Expand Down

0 comments on commit 4675443

Please sign in to comment.