From cc3289a785448ce82f954f3a43cadbce7625ed1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Tue, 1 Dec 2015 21:03:42 +0100 Subject: [PATCH] avocado.core.runner: Get proper status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently the test status was only updated on `TestStatus.check` method, which was also used in `TestStatus.abort`. But the meaning of `check` return is whether the job was interrupted. It does not mean the status is valid, which in some cases might have reported the test status `None`. This patch reworks the way we interact with `TestStatus`. It contains `interrupt` variable, which means the test was interrupted and we should leave the execution. It still have the `status` variable, which contains the status, but now those two variables are automatically updated on query (using __getattribute__). Signed-off-by: Lukáš Doktor --- avocado/core/runner.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/avocado/core/runner.py b/avocado/core/runner.py index c2371b1e..743f31c4 100644 --- a/avocado/core/runner.py +++ b/avocado/core/runner.py @@ -51,6 +51,7 @@ class TestStatus(object): self.queue = queue self._early_status = None self.status = {} + self.interrupt = None @property def early_status(self): @@ -76,6 +77,12 @@ class TestStatus(object): else: # Not an early_status message queue.append(msg) + def __getattribute__(self, name): + # Update state before returning the value + if name in ("status", "interrupt"): + self._tick() + return super(TestStatus, self).__getattribute__(name) + def wait_for_early_status(self, proc, timeout): """ Wait until early_status is obtained @@ -97,12 +104,10 @@ class TestStatus(object): raise exceptions.TestError(msg) time.sleep(0) - def check(self): + def _tick(self): """ - Check if there are messages queued and handle them - :return: True if everything is ok, False on interruption (break) + Process the queue and update current status """ - res = True while not self.queue.empty(): msg = self.queue.get() if "func_at_exit" in msg: @@ -112,8 +117,7 @@ class TestStatus(object): msg.get("once", False)) elif not msg.get("running", True): self.status = msg - res = False - continue + self.interrupt = True elif "paused" in msg: self.status = msg self.job.result_proxy.notify_progress(False) @@ -123,7 +127,6 @@ class TestStatus(object): self.job.view.notify(event='partial', msg=reason) else: # test_status self.status = msg - return res def abort(self, test_alive, started, timeout, first, step): """ @@ -134,7 +137,7 @@ class TestStatus(object): :param first: Delay before first check :param step: Step between checks for the status """ - if test_alive and wait.wait_for(lambda: not self.check(), timeout, + if test_alive and wait.wait_for(lambda: self.status, timeout, first, step): return self.status else: @@ -270,7 +273,7 @@ class TestRunner(object): break wait.wait_for(lambda: not queue.empty() or not proc.is_alive(), cycle_timeout, first, step) - if not test_status.check(): + if test_status.interrupt: break if proc.is_alive(): if ctrl_c_count == 0: @@ -300,7 +303,6 @@ class TestRunner(object): os.kill(proc.pid, signal.SIGKILL) # Get/update the test status - test_status.check() if test_status.status: test_state = test_status.status else: -- GitLab