Skip to content

Commit

Permalink
test: Fix pytest race in test_spawn_broken_pipe()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
martinpitt committed Oct 12, 2023
1 parent 953a6ee commit 934c61c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions test/pytest/test_peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 934c61c

Please sign in to comment.