From 934c61c914639a3390e85cdbe38fa80950811635 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 12 Oct 2023 11:45:06 +0200 Subject: [PATCH] test: Fix pytest race in test_spawn_broken_pipe() The static `time.sleep(0.1)` was racy: On slow architectures like Debian mips [1] it repeatedly fails, and it even sometimes fails on GitHub actions. Keep writing until the transport closes, so that we are guaranteed to eventually run into a BrokenPipeError. Fixes #19469 [1] https://buildd.debian.org/status/logs.php?pkg=cockpit&ver=302-1&arch=mips64el --- test/pytest/test_peer.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/pytest/test_peer.py b/test/pytest/test_peer.py index f336f85d157b..78e9a7028700 100644 --- a/test/pytest/test_peer.py +++ b/test/pytest/test_peer.py @@ -189,8 +189,10 @@ def __init__(self, *, specific_error=False): async def do_connect_transport(self) -> None: transport = await self.spawn(['sh', '-c', 'exit 9'], ()) assert isinstance(transport, SubprocessTransport) - time.sleep(0.1) # sync! increase chance for process to end already - transport.write(b'abcdefg\n') + # The process will exit soon — try writing to it until a write fails. + while not transport.is_closing(): + transport.write(b'x') + time.sleep(0.1) while transport.get_returncode() is None: await asyncio.sleep(0.1) if self.specific_error: