Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix regrtest timeout for subprocesses
  • Loading branch information
Joannah nanjekye authored and vstinner committed Aug 14, 2019
commit 172ca99ff3f4d2bd27f4ed0058f9beda93a370e9
4 changes: 3 additions & 1 deletion Lib/test/libregrtest/main.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from test.libregrtest.runtest import (
findtests, runtest, get_abs_module,
STDTESTS, NOTTESTS, PASSED, FAILED, ENV_CHANGED, SKIPPED, RESOURCE_DENIED,
INTERRUPTED, CHILD_ERROR, TEST_DID_NOT_RUN,
INTERRUPTED, CHILD_ERROR, TEST_DID_NOT_RUN, TIMEOUT,
PROGRESS_MIN_TIME, format_test_result, is_failed)
from test.libregrtest.setup import setup_tests
from test.libregrtest.pgo import setup_pgo_tests
Expand Down Expand Up @@ -115,6 +115,8 @@ def accumulate_result(self, result, rerun=False):
self.run_no_tests.append(test_name)
elif ok == INTERRUPTED:
self.interrupted = True
elif ok == TIMEOUT:
self.bad.append(test_name)
else:
raise ValueError("invalid test result: %r" % ok)

Expand Down
5 changes: 4 additions & 1 deletion Lib/test/libregrtest/runtest.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
INTERRUPTED = -4
CHILD_ERROR = -5 # error in a child process
TEST_DID_NOT_RUN = -6
TIMEOUT = -7

_FORMAT_TEST_RESULT = {
PASSED: '%s passed',
Expand All @@ -35,6 +36,7 @@
INTERRUPTED: '%s interrupted',
CHILD_ERROR: '%s crashed',
TEST_DID_NOT_RUN: '%s run no tests',
TIMEOUT: '%s test did not finish',
}

# Minimum duration of a test to display its duration or to mention that
Expand Down Expand Up @@ -66,7 +68,7 @@

def is_failed(result, ns):
ok = result.result
if ok in (PASSED, RESOURCE_DENIED, SKIPPED, TEST_DID_NOT_RUN):
if ok in (PASSED, RESOURCE_DENIED, SKIPPED, TEST_DID_NOT_RUN, TIMEOUT):
return False
if ok == ENV_CHANGED:
return ns.fail_env_changed
Expand Down Expand Up @@ -179,6 +181,7 @@ def runtest(ns, test_name):
FAILED test failed
PASSED test passed
EMPTY_TEST_SUITE test ran no subtests.
TIMEOUT test failed due to timeout

If ns.xmlpath is not None, xml_data is a list containing each
generated testsuite element.
Expand Down
16 changes: 12 additions & 4 deletions Lib/test/libregrtest/runtest_mp.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from test.libregrtest.runtest import (
runtest, INTERRUPTED, CHILD_ERROR, PROGRESS_MIN_TIME,
format_test_result, TestResult, is_failed)
format_test_result, TestResult, is_failed, TIMEOUT)
from test.libregrtest.setup import setup_tests
from test.libregrtest.utils import format_duration

Expand Down Expand Up @@ -137,6 +137,13 @@ def kill(self):
popen.stdout.close()
popen.stderr.close()

def time_result(self, test_name, error_type):
test_time = time.monotonic() - self.start_time
result = TestResult(test_name, error_type, test_time, None)
stdout = stderr = ''
err_msg = None
return result, stdout, stderr, err_msg

def _runtest(self, test_name):
try:
self.start_time = time.monotonic()
Expand All @@ -154,7 +161,9 @@ def _runtest(self, test_name):
raise ExitThread

try:
stdout, stderr = popen.communicate()
stdout, stderr = popen.communicate(timeout=self.ns.timeout)
except subprocess.TimeoutExpired:
result, stdout, stderr, err_msg = self.time_result(test_name, TIMEOUT)
except OSError:
if self._killed:
# kill() has been called: communicate() fails
Expand Down Expand Up @@ -191,8 +200,7 @@ def _runtest(self, test_name):
err_msg = "Failed to parse worker JSON: %s" % exc

if err_msg is not None:
test_time = time.monotonic() - self.start_time
result = TestResult(test_name, CHILD_ERROR, test_time, None)
result, stdout, stderr, err_msg = self.time_result(test_name, CHILD_ERROR)

return MultiprocessResult(result, stdout, stderr, err_msg)

Expand Down
Empty file modified Lib/test/test_os.py
100644 → 100755
Empty file.