Skip to content

Commit 03c2da4

Browse files
committed
gh-47798: Fix flaky pipeline tests where downstream exits without reading
In tests where the second command exits immediately (sys.exit(N)) without reading stdin, the first command's stdout flush during interpreter shutdown can hit a readerless pipe and yield exit code 120, breaking assertions on returncodes[0] == 0. Seen on Windows free-threading and FreeBSD refleak buildbots. The first command's output is unused in these tests; switch it to "pass".
1 parent ae5a6b2 commit 03c2da4

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Lib/test/test_subprocess.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ def test_pipeline_error_check(self):
21502150
"""Test that check=True raises PipelineError on failure"""
21512151
with self.assertRaises(subprocess.PipelineError) as cm:
21522152
subprocess.run_pipeline(
2153-
[sys.executable, "-c", 'print("hello")'],
2153+
[sys.executable, "-c", "pass"],
21542154
[sys.executable, "-c", "import sys; sys.exit(1)"],
21552155
capture_output=True, check=True
21562156
)
@@ -2261,7 +2261,7 @@ def test_pipeline_completed_repr(self):
22612261
def test_pipeline_check_returncodes_method(self):
22622262
"""Test CompletedPipeline.check_returncodes() method"""
22632263
result = subprocess.run_pipeline(
2264-
[sys.executable, "-c", 'print("hello")'],
2264+
[sys.executable, "-c", "pass"],
22652265
[sys.executable, "-c", "import sys; sys.exit(5)"],
22662266
capture_output=True
22672267
)
@@ -2996,7 +2996,10 @@ def test_command_in_pipeline_error(self):
29962996
stderr=subprocess.DEVNULL)
29972997
try:
29982998
subprocess.run_pipeline(
2999-
[sys.executable, "-c", 'print("x")'],
2999+
# cmd0 must not write to stdout: cmd1 exits without
3000+
# reading, and a flush to a readerless pipe during
3001+
# interpreter shutdown can yield exit code 120.
3002+
[sys.executable, "-c", "pass"],
30003003
explicit,
30013004
capture_output=True, check=True,
30023005
)

0 commit comments

Comments
 (0)