Skip to content

Commit

Permalink
Merge pull request #103 from lmr/test-subprocess-improvements
Browse files Browse the repository at this point in the history
Test subprocess improvements
  • Loading branch information
ruda committed Jun 13, 2014
2 parents 9ccc2d7 + 6d26732 commit 80cf4e0
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions avocado/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import os
import signal
import sys
import time
import traceback
import uuid

Expand Down Expand Up @@ -103,7 +104,7 @@ def timeout_handler(signum, frame):
e_msg = "Timeout reached waiting for %s to end" % instance
raise exceptions.TestTimeoutError(e_msg)

signal.signal(signal.SIGTERM, timeout_handler)
signal.signal(signal.SIGUSR1, timeout_handler)
try:
instance.run_avocado()
finally:
Expand All @@ -117,6 +118,11 @@ def run(self, params_list):
:return: a list of test failures.
"""
def send_signal(p, sig):
if p.exitcode is None:
os.kill(p.pid, sig)
time.sleep(0.1)

failures = []
self.result.start_tests()
q = multiprocessing.Queue()
Expand All @@ -136,12 +142,14 @@ def run(self, params_list):
if timeout is not None:
timeout = float(timeout)
# Wait for the test to end for [timeout] s
p.join(timeout)
# If there's no exit code, the test is still running.
# It must be terminated.
if p.exitcode is None:
p.terminate()
test_instance = q.get()
try:
test_instance = q.get(timeout=timeout)
except Exception:
# If there's nothing inside the queue after timeout, the process
# must be terminated.
send_signal(p, signal.SIGUSR1)
test_instance = q.get(timeout=0.1)

self.result.check_test(test_instance)
if not status.mapping[test_instance.status]:
failures.append(test_instance.name)
Expand Down

0 comments on commit 80cf4e0

Please sign in to comment.