Skip to content

Commit aa2c4e4

Browse files
[3.13] gh-116742: Fix subprocess test_check_output_timeout() (GH-130836) (#130873)
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 6321e1a commit aa2c4e4

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
@@ -1693,20 +1685,11 @@ def test_check_output_stdin_with_input_arg(self):
16931685
self.assertIn('stdin', c.exception.args[0])
16941686
self.assertIn('input', c.exception.args[0])
16951687

1696-
@support.requires_resource('walltime')
16971688
def test_check_output_timeout(self):
16981689
with self.assertRaises(subprocess.TimeoutExpired) as c:
1699-
cp = self.run_python((
1700-
"import sys, time\n"
1701-
"sys.stdout.write('BDFL')\n"
1702-
"sys.stdout.flush()\n"
1703-
"time.sleep(3600)"),
1704-
# Some heavily loaded buildbots (sparc Debian 3.x) require
1705-
# this much time to start and print.
1706-
timeout=3, stdout=subprocess.PIPE)
1707-
self.assertEqual(c.exception.output, b'BDFL')
1708-
# output is aliased to stdout
1709-
self.assertEqual(c.exception.stdout, b'BDFL')
1690+
cp = self.run_python(
1691+
"import time; time.sleep(3600)",
1692+
timeout=0.1, stdout=subprocess.PIPE)
17101693

17111694
def test_run_kwargs(self):
17121695
newenv = os.environ.copy()

0 commit comments

Comments
 (0)