Skip to content

Commit ce7ffff

Browse files
authored
Merge branch 'main' into publish-provenance
2 parents 878acbc + 8d20b7b commit ce7ffff

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎tests/test_utils.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,19 @@ def test_pipeline_writer_relay_lends_only_while_a_producer_waits(pauses) -> None
478478
waiting, command code gets the terminal back, whether or not the consumer has read all
479479
its output yet. That is as between cmd2's own writes.
480480
"""
481+
import fcntl
481482
import subprocess
482483
import threading
483484

484-
# More than the relay and both pipes hold, so the child blocks until the consumer reads. What remains after the consumer's
485-
# first read fits, so the child can then finish.
486-
payload = b"x" * 280000
487-
first_read = 200000 if pauses else len(payload)
488485
read_fd, write_fd = os.pipe()
486+
# Size the payload from the consumer's pipe. Linux reports its capacity, which follows the page size (16 pages by
487+
# default); macOS and the BSDs cap a pipe at 64 KiB.
488+
capacity = fcntl.fcntl(write_fd, fcntl.F_GETPIPE_SZ) if hasattr(fcntl, "F_GETPIPE_SZ") else 65536
489+
# More than the relay and both pipes hold, so the child blocks until the consumer reads. What remains after the consumer's
490+
# first read fits, so the child can then finish. It is also more than the consumer's pipe holds, so part of it is still
491+
# in the relay when cmd2 writes after it.
492+
payload = b"x" * (2 * capacity + 2 * 65536)
493+
first_read = len(payload) - capacity - 16384 if pauses else len(payload)
489494
received = bytearray()
490495
lent = threading.Event()
491496
resume = threading.Event()

0 commit comments

Comments
 (0)