Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test subprocess improvements #103

Merged
merged 1 commit into from
Jun 13, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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