validate: launcher: Split process_update() out of wait_process()

Patch 1/4 to make TestManager handle waiting for processes instead of
expecting each Test to do it.
This commit is contained in:
Ramiro Polla 2015-01-16 18:57:06 +01:00 committed by Thibault Saunier
parent d12f55daf4
commit 498f7002f3

View file

@ -192,16 +192,25 @@ class Test(Loggable):
return Result.NOT_RUN return Result.NOT_RUN
def wait_process(self): def wait_process(self):
last_val = 0 self.last_val = 0
last_change_ts = time.time() self.last_change_ts = time.time()
start_ts = time.time() self.start_ts = time.time()
while True: while True:
# Check process every second for timeout # Check process every second for timeout
self.thread.join(1.0) self.thread.join(1.0)
if self.process_update():
break
self.check_results()
def process_update(self):
"""
Returns True when process has finished running or has timed out.
"""
self.process.poll() self.process.poll()
if self.process.returncode is not None: if self.process.returncode is not None:
break return True
val = self.get_current_value() val = self.get_current_value()
@ -209,33 +218,33 @@ class Test(Loggable):
if val is Result.NOT_RUN: if val is Result.NOT_RUN:
# The get_current_value logic is not implemented... dumb # The get_current_value logic is not implemented... dumb
# timeout # timeout
if time.time() - last_change_ts > self.timeout: if time.time() - self.last_change_ts > self.timeout:
self.set_result(Result.TIMEOUT) self.set_result(Result.TIMEOUT)
break return True
continue return False
elif val is Result.FAILED: elif val is Result.FAILED:
break return True
elif val is Result.KNOWN_ERROR: elif val is Result.KNOWN_ERROR:
break return True
self.log("New val %s" % val) self.log("New val %s" % val)
if val == last_val: if val == self.last_val:
delta = time.time() - last_change_ts delta = time.time() - self.last_change_ts
self.debug("%s: Same value for %d/%d seconds" % self.debug("%s: Same value for %d/%d seconds" %
(self, delta, self.timeout)) (self, delta, self.timeout))
if delta > self.timeout: if delta > self.timeout:
self.set_result(Result.TIMEOUT) self.set_result(Result.TIMEOUT)
break return True
elif self.hard_timeout and time.time() - start_ts > self.hard_timeout: elif self.hard_timeout and time.time() - self.start_ts > self.hard_timeout:
self.set_result( self.set_result(
Result.TIMEOUT, "Hard timeout reached: %d secs" % self.hard_timeout) Result.TIMEOUT, "Hard timeout reached: %d secs" % self.hard_timeout)
break return True
else: else:
last_change_ts = time.time() self.last_change_ts = time.time()
last_val = val self.last_val = val
self.check_results() return False
def get_subproc_env(self): def get_subproc_env(self):
return os.environ return os.environ