Skip to content

Commit

Permalink
Move instrumented test monitoring into method
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
richtja committed Nov 9, 2023
1 parent cf16632 commit cf0d373
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions avocado/plugins/runners/avocado_instrumented.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit cf0d373

Please sign in to comment.