Skip to content

Commit ed015d0

Browse files
[3.12] gh-116742: Fix subprocess test_check_output_timeout() (GH-130836) (#130874)
gh-116742: Fix subprocess test_check_output_timeout() (GH-130836) Fix a race condition in test_check_output_timeout() of test_subprocess. Don't write into stdout anymore, since there is no reliable way to synchronize the parent and the child processes. Change the timeout from 3 seconds to 0.1 seconds, and remove @requires_resource('walltime') decorator. (cherry picked from commit 67a942d) Co-authored-by: Victor Stinner <[email protected]>
1 parent 8fe011a commit ed015d0

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

Lib/test/test_subprocess.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -268,21 +268,13 @@ def test_check_output_stdin_with_input_arg(self):
268268
self.assertIn('stdin', c.exception.args[0])
269269
self.assertIn('input', c.exception.args[0])
270270

271-
@support.requires_resource('walltime')
272271
def test_check_output_timeout(self):
273272
# check_output() function with timeout arg
274273
with self.assertRaises(subprocess.TimeoutExpired) as c:
275274
output = subprocess.check_output(
276275
[sys.executable, "-c",
277-
"import sys, time\n"
278-
"sys.stdout.write('BDFL')\n"
279-
"sys.stdout.flush()\n"
280-
"time.sleep(3600)"],
281-
# Some heavily loaded buildbots (sparc Debian 3.x) require
282-
# this much time to start and print.
283-
timeout=3)
284-
self.fail("Expected TimeoutExpired.")
285-
self.assertEqual(c.exception.output, b'BDFL')
276+
"import time; time.sleep(3600)"],
277+
timeout=0.1)
286278

287279
def test_call_kwargs(self):
288280
# call() function with keyword args
@@ -1708,20 +1700,11 @@ def test_check_output_stdin_with_input_arg(self):
17081700
self.assertIn('stdin', c.exception.args[0])
17091701
self.assertIn('input', c.exception.args[0])
17101702

1711-
@support.requires_resource('walltime')
17121703
def test_check_output_timeout(self):
17131704
with self.assertRaises(subprocess.TimeoutExpired) as c:
1714-
cp = self.run_python((
1715-
"import sys, time\n"
1716-
"sys.stdout.write('BDFL')\n"
1717-
"sys.stdout.flush()\n"
1718-
"time.sleep(3600)"),
1719-
# Some heavily loaded buildbots (sparc Debian 3.x) require
1720-
# this much time to start and print.
1721-
timeout=3, stdout=subprocess.PIPE)
1722-
self.assertEqual(c.exception.output, b'BDFL')
1723-
# output is aliased to stdout
1724-
self.assertEqual(c.exception.stdout, b'BDFL')
1705+
cp = self.run_python(
1706+
"import time; time.sleep(3600)",
1707+
timeout=0.1, stdout=subprocess.PIPE)
17251708

17261709
def test_run_kwargs(self):
17271710
newenv = os.environ.copy()

0 commit comments

Comments
 (0)