From 8b149777e254369c8e41b0b13dfb3c3a955f9e58 Mon Sep 17 00:00:00 2001 From: Steve Traylen Date: Tue, 17 Nov 2026 20:18:22 +0100 Subject: [PATCH 1/4] test: wait for consumer before checking its read On ppc64le, test_pipeline_writer_relay_lends_only_while_a_producer_waits[True] failed with: AssertionError: assert 1114112 == 1163264 The child's last write unblocks once the relay has forwarded about capacity + 65536 bytes, 1114112 with 64 KiB pages. The consumer may still need more forwarded to reach first_read, and the test asserted as soon as the lend was returned, without waiting for it. Wait up to 5 seconds for the consumer to reach first_read. Its reads are capped there, so the equality check still holds. --- tests/test_utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 659d175bb..e9125d380 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -539,6 +539,10 @@ def drain() -> None: time.sleep(0.01) assert not lends if pauses: + # The child can exit before the consumer has read all of its first page, so give it time. + deadline = time.monotonic() + 5 + while len(received) < first_read and time.monotonic() < deadline: + time.sleep(0.01) assert len(received) == first_read # cmd2's own writes follow what the child wrote, which is still pending. threading.Timer(0.3, resume.set).start() From 7dc92371d33d6fc33cbbc7ec5510ab727d4b27a4 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:00:32 -0500 Subject: [PATCH 2/4] test: signal the relay consumer's pause with an event The consumer now sets an event once it has read its first page, and the test waits on that instead of polling the byte count. A timeout fails with a message that says so, where it used to look like the byte-count mismatch of the original race. The consumer's first read loop also stops on end of file, so a relay that closes the pipe early fails the test instead of spinning. --- tests/test_utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index e9125d380..02035311d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -499,6 +499,7 @@ def test_pipeline_writer_relay_lends_only_while_a_producer_waits(pauses) -> None first_read = len(payload) - capacity - 16384 if pauses else len(payload) received = bytearray() lent = threading.Event() + paused = threading.Event() resume = threading.Event() lends = [] @@ -516,7 +517,12 @@ def drain() -> None: # the next key. lent.wait(10) while len(received) < first_read: - received.extend(os.read(read_fd, min(65536, first_read - len(received)))) + chunk = os.read(read_fd, min(65536, first_read - len(received))) + if not chunk: + # The relay closed the pipe early. Stop here, so the test fails on what is missing instead of spinning. + return + received.extend(chunk) + paused.set() resume.wait(10) while chunk := os.read(read_fd, 65536): received.extend(chunk) @@ -539,11 +545,9 @@ def drain() -> None: time.sleep(0.01) assert not lends if pauses: - # The child can exit before the consumer has read all of its first page, so give it time. - deadline = time.monotonic() + 5 - while len(received) < first_read and time.monotonic() < deadline: - time.sleep(0.01) - assert len(received) == first_read + # The child can exit before the consumer has read all of its first page, so give it time. Its reads stop at that + # page until resumed, so the rest is still in the relay. + assert paused.wait(5), f"the consumer read {len(received)} of its first {first_read} bytes in time" # cmd2's own writes follow what the child wrote, which is still pending. threading.Timer(0.3, resume.set).start() assert writer.write(b"end") == 3 From dafc0886a106bf1951df8314cc2b7111d18d33d8 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Tue, 17 Nov 2026 19:06:03 -0500 Subject: [PATCH 3/4] test: release the relay consumer when the test fails early Cleanup set resume but not lent, so a test that failed before the first lend left the consumer in lent.wait(10) while cleanup joined it for the same 10 seconds. Each such failure took 10 seconds, and a join that lost the race closed the read descriptor under a live thread. Set lent in cleanup as well. Correct the comment on the consumer's end-of-file check, and the reason the previous commit gave for it. The writer keeps its own write end of the pipe, so the relay cannot close it early. End of file arrives only once cleanup closes the writer, and the check stops the consumer spinning on empty reads after that. --- tests/test_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 02035311d..3be8bac8c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -519,7 +519,8 @@ def drain() -> None: while len(received) < first_read: chunk = os.read(read_fd, min(65536, first_read - len(received))) if not chunk: - # The relay closed the pipe early. Stop here, so the test fails on what is missing instead of spinning. + # End of file arrives only once the test's cleanup closes the writer. Reaching it here means the output fell + # short, so stop instead of spinning on empty reads. return received.extend(chunk) paused.set() @@ -552,6 +553,8 @@ def drain() -> None: threading.Timer(0.3, resume.set).start() assert writer.write(b"end") == 3 finally: + # Release the consumer wherever it waits, so a test that fails before a lend does not hold up the join. + lent.set() resume.set() writer.close() consumer.join(10) From 028faa2288ede8a5eb0487ae08b12f928636c1a2 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Tue, 17 Nov 2026 19:25:45 -0500 Subject: [PATCH 4/4] test: keep the relay consumer waiting until the test releases it A timeout on either of the consumer's waits let a slow run read ahead: past its first page before cmd2's write, or before any lend. The test could then pass without exercising what it is for. Its cleanup releases both waits, so neither needs a timeout to end. --- tests/test_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 3be8bac8c..8ec49b0db 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -514,8 +514,9 @@ def _lend_terminal(): def drain() -> None: # Like a pager waiting for a key, drain nothing until lent the terminal. Then read a page, or all of it, and wait for - # the next key. - lent.wait(10) + # the next key. Neither wait has a timeout, which would let a slow test read ahead unnoticed: the test's cleanup + # releases both. + lent.wait() while len(received) < first_read: chunk = os.read(read_fd, min(65536, first_read - len(received))) if not chunk: @@ -524,7 +525,7 @@ def drain() -> None: return received.extend(chunk) paused.set() - resume.wait(10) + resume.wait() while chunk := os.read(read_fd, 65536): received.extend(chunk)