From 3f53c221c86c0116b9463e1e11dd74728dfd44e3 Mon Sep 17 00:00:00 2001 From: ddidderr Date: Wed, 10 Jun 2026 00:20:10 +0200 Subject: [PATCH] test: tolerate closed stdin in chunk-size failure The chunk-size-zero regression test spawned fcry with stdin piped and unconditionally unwrapped the write into that pipe. That made the test depend on scheduler timing: the child may validate --chunk-size 0, report the error, and exit before it has drained stdin. Treat BrokenPipe as the expected early-exit shape for this failing command, while still failing on any other write error and still asserting that the process exits unsuccessfully. The valid empty-stdin chunk-size case remains unchanged. Test Plan: - cargo fmt --check - cargo test - cargo clippy --all-targets -- -D warnings - git diff --check Refs: none --- tests/roundtrip.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/roundtrip.rs b/tests/roundtrip.rs index eccfdbd..70e867f 100644 --- a/tests/roundtrip.rs +++ b/tests/roundtrip.rs @@ -7,7 +7,7 @@ // wrong key, truncation, bad magic). use std::fs; -use std::io::Write; +use std::io::{ErrorKind, Write}; use std::process::{Command, Stdio}; use assert_cmd::cargo::CommandCargoExt; @@ -915,7 +915,14 @@ fn stdin_chunk_size_zero_fails_but_empty_valid_chunk_succeeds() { .stderr(Stdio::piped()) .spawn() .unwrap(); - bad.stdin.as_mut().unwrap().write_all(b"x").unwrap(); + // Invalid options can make the child exit before it drains stdin. + if let Err(err) = bad.stdin.as_mut().unwrap().write_all(b"x") { + assert_eq!( + err.kind(), + ErrorKind::BrokenPipe, + "unexpected stdin write error for failing chunk-size 0 process: {err}" + ); + } let bad_out = bad.wait_with_output().unwrap(); assert!(!bad_out.status.success(), "chunk-size 0 should fail");