Skip to content

Commit 67a942d

Browse files
authored
gh-116742: Fix subprocess test_check_output_timeout() (#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.
1 parent 63d25f8 commit 67a942d

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
@@ -269,21 +269,13 @@ def test_check_output_stdin_with_input_arg(self):
269269
self.assertIn('stdin', c.exception.args[0])
270270
self.assertIn('input', c.exception.args[0])
271271

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

288280
def test_call_kwargs(self):
289281
# call() function with keyword args
@@ -1694,20 +1686,11 @@ def test_check_output_stdin_with_input_arg(self):
16941686
self.assertIn('stdin', c.exception.args[0])
16951687
self.assertIn('input', c.exception.args[0])
16961688

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

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

0 commit comments

Comments
 (0)