From 1dfce2f77a2af111a7a31a6f9c5a962ba02b04dc Mon Sep 17 00:00:00 2001 From: Joannah nanjekye Date: Tue, 9 Jul 2019 14:43:53 -0300 Subject: [PATCH 1/4] Fix regrtest timeout for subprocesses --- Lib/test/libregrtest/main.py | 4 +++- Lib/test/libregrtest/runtest.py | 5 ++++- Lib/test/libregrtest/runtest_mp.py | 16 ++++++++++++---- Lib/test/test_os.py | 0 4 files changed, 19 insertions(+), 6 deletions(-) mode change 100644 => 100755 Lib/test/libregrtest/main.py mode change 100644 => 100755 Lib/test/libregrtest/runtest.py mode change 100644 => 100755 Lib/test/libregrtest/runtest_mp.py mode change 100644 => 100755 Lib/test/test_os.py diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py old mode 100644 new mode 100755 index e2274254fdb89c..7d6a62863599bd --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -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.utils import removepy, count, format_duration, printlist @@ -114,6 +114,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) diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py old mode 100644 new mode 100755 index a43b7666cd1e35..78a567f3173c9a --- a/Lib/test/libregrtest/runtest.py +++ b/Lib/test/libregrtest/runtest.py @@ -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', @@ -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 @@ -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 @@ -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. diff --git a/Lib/test/libregrtest/runtest_mp.py b/Lib/test/libregrtest/runtest_mp.py old mode 100644 new mode 100755 index aa2409b4ef7985..9bc56085fea3b6 --- a/Lib/test/libregrtest/runtest_mp.py +++ b/Lib/test/libregrtest/runtest_mp.py @@ -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 @@ -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() @@ -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 @@ -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) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py old mode 100644 new mode 100755 From 199083c01d02aed694bdee67cf827cd30081d281 Mon Sep 17 00:00:00 2001 From: Joannah nanjekye Date: Tue, 9 Jul 2019 16:32:12 -0300 Subject: [PATCH 2/4] Some edits to test --- Lib/test/libregrtest/runtest_mp.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/test/libregrtest/runtest_mp.py b/Lib/test/libregrtest/runtest_mp.py index 9bc56085fea3b6..10d7c7ce0edd68 100755 --- a/Lib/test/libregrtest/runtest_mp.py +++ b/Lib/test/libregrtest/runtest_mp.py @@ -163,7 +163,12 @@ def _runtest(self, test_name): try: stdout, stderr = popen.communicate(timeout=self.ns.timeout) except subprocess.TimeoutExpired: + if self._killed: + # kill() has been called: communicate() fails + # on reading closed stdout/stderr + raise ExitThread result, stdout, stderr, err_msg = self.time_result(test_name, TIMEOUT) + raise except OSError: if self._killed: # kill() has been called: communicate() fails From 529f84799c694917e34a48c1bff3f9ced046cab5 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2019 19:38:29 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-3753.GX7s8S.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-3753.GX7s8S.rst diff --git a/Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-3753.GX7s8S.rst b/Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-3753.GX7s8S.rst new file mode 100644 index 00000000000000..dac25a828a32d3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-3753.GX7s8S.rst @@ -0,0 +1 @@ +Fix `regrtest` timeout for subprocesses. \ No newline at end of file From 6a802df2b83f9b5d81f63a9afc21d87d255bcdb9 Mon Sep 17 00:00:00 2001 From: nanjekyejoannah Date: Thu, 18 Jul 2019 12:36:37 -0300 Subject: [PATCH 4/4] Revert file mode changes --- Lib/test/libregrtest/main.py | 0 Lib/test/libregrtest/runtest.py | 4 ++-- Lib/test/libregrtest/runtest_mp.py | 0 Lib/test/test_os.py | 0 .../next/Library/2019-07-09-19-38-26.bpo-3753.GX7s8S.rst | 1 - .../next/Library/2019-07-09-19-38-26.bpo-37531.GX7s8S.rst | 3 +++ 6 files changed, 5 insertions(+), 3 deletions(-) mode change 100755 => 100644 Lib/test/libregrtest/main.py mode change 100755 => 100644 Lib/test/libregrtest/runtest.py mode change 100755 => 100644 Lib/test/libregrtest/runtest_mp.py mode change 100755 => 100644 Lib/test/test_os.py delete mode 100644 Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-3753.GX7s8S.rst create mode 100644 Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-37531.GX7s8S.rst diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py old mode 100755 new mode 100644 diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py old mode 100755 new mode 100644 index 78a567f3173c9a..b24015af009a09 --- a/Lib/test/libregrtest/runtest.py +++ b/Lib/test/libregrtest/runtest.py @@ -36,7 +36,7 @@ INTERRUPTED: '%s interrupted', CHILD_ERROR: '%s crashed', TEST_DID_NOT_RUN: '%s run no tests', - TIMEOUT: '%s test did not finish', + TIMEOUT: '%s timed out', } # Minimum duration of a test to display its duration or to mention that @@ -181,7 +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 + TIMEOUT test timd out. If ns.xmlpath is not None, xml_data is a list containing each generated testsuite element. diff --git a/Lib/test/libregrtest/runtest_mp.py b/Lib/test/libregrtest/runtest_mp.py old mode 100755 new mode 100644 diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py old mode 100755 new mode 100644 diff --git a/Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-3753.GX7s8S.rst b/Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-3753.GX7s8S.rst deleted file mode 100644 index dac25a828a32d3..00000000000000 --- a/Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-3753.GX7s8S.rst +++ /dev/null @@ -1 +0,0 @@ -Fix `regrtest` timeout for subprocesses. \ No newline at end of file diff --git a/Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-37531.GX7s8S.rst b/Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-37531.GX7s8S.rst new file mode 100644 index 00000000000000..aa5f0f495ed01e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-07-09-19-38-26.bpo-37531.GX7s8S.rst @@ -0,0 +1,3 @@ +The change only impacts "python3 -m test -jN --timeout=TIMEOUT", +it ensures that a worker process is stopped with a timeout if it +runs longer than `TIMEOUT` seconds.