From cf0d373429f6dd4250d66e2d0baabbbc3fd700f5 Mon Sep 17 00:00:00 2001 From: Jan Richter Date: Wed, 8 Nov 2023 17:06:45 +0100 Subject: [PATCH] Move instrumented test monitoring into method It will move the message monitoring loop for avocado-instrumented test into its own method. With this change, we can reuse the monitoring loop. Signed-off-by: Jan Richter --- .../plugins/runners/avocado_instrumented.py | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/avocado/plugins/runners/avocado_instrumented.py b/avocado/plugins/runners/avocado_instrumented.py index f3db717ce9..55b80f5d00 100644 --- a/avocado/plugins/runners/avocado_instrumented.py +++ b/avocado/plugins/runners/avocado_instrumented.py @@ -129,6 +129,28 @@ def _run_avocado(runnable, queue): ) ) + @staticmethod + def _monitor(proc, time_started, queue): + timeout = float("inf") + next_status_time = None + while True: + time.sleep(RUNNER_RUN_CHECK_INTERVAL) + now = time.monotonic() + if queue.empty(): + if next_status_time is None or now > next_status_time: + next_status_time = now + RUNNER_RUN_STATUS_INTERVAL + yield messages.RunningMessage.get() + if (now - time_started) > timeout: + proc.terminate() + else: + message = queue.get() + if message.get("type") == "early_state": + timeout = float(message.get("timeout") or float("inf")) + else: + yield message + if message.get("status") == "finished": + break + def run(self, runnable): # pylint: disable=W0201 self.runnable = runnable @@ -142,28 +164,9 @@ def run(self, runnable): process.start() time_started = time.monotonic() + for message in self._monitor(process, time_started, queue): + yield message - timeout = float("inf") - next_status_time = None - while True: - time.sleep(RUNNER_RUN_CHECK_INTERVAL) - now = time.monotonic() - if queue.empty(): - if next_status_time is None or now > next_status_time: - next_status_time = now + RUNNER_RUN_STATUS_INTERVAL - yield messages.RunningMessage.get() - if (now - time_started) > timeout: - process.terminate() - yield messages.FinishedMessage.get("interrupted", "timeout") - break - else: - message = queue.get() - if message.get("type") == "early_state": - timeout = float(message.get("timeout") or float("inf")) - else: - yield message - if message.get("status") == "finished": - break except Exception as e: yield messages.StderrMessage.get(traceback.format_exc()) yield messages.FinishedMessage.get(