提交 cc3289a7 编写于 作者: L Lukáš Doktor

avocado.core.runner: Get proper status

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: NLukáš Doktor <ldoktor@redhat.com>
上级 0ba51736
......@@ -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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册