Skip to content

Commit 32640ee

Browse files
committed
Make want_for_stdout more defensive
1 parent e1bf539 commit 32640ee

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

rustls-libssl/tests/runner.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,18 +557,27 @@ fn wait_for_port(port: u16) -> Option<()> {
557557
/// on a given `Child`, this must not read bytes from its `stdout`
558558
/// that appear after `expected`.
559559
fn wait_for_stdout(stream: &mut Child, expected: &[u8]) {
560-
let stdout = stream.stdout.as_mut().unwrap();
561-
562-
let mut buffer = Vec::with_capacity(1024);
560+
let mut buffer = Vec::with_capacity(128);
563561

564562
loop {
565563
let mut input = [0u8];
566-
let new = stdout.read(&mut input).unwrap();
567-
assert_eq!(new, 1);
564+
let new = stream.stdout.as_mut().unwrap().read(&mut input).unwrap();
565+
assert_eq!(new, 1, "stdout EOF -- read so far {buffer:?}");
568566
buffer.push(input[0]);
569567

570568
if buffer.ends_with(expected) {
571569
return;
572570
}
571+
572+
assert!(
573+
buffer.len() < 128,
574+
"{expected:?} did not appear in first part of {stream:?} (instead it was {buffer:?}"
575+
);
576+
577+
match stream.try_wait() {
578+
Ok(Some(status)) => panic!("process exited already with {status}"),
579+
Ok(None) => {}
580+
Err(e) => panic!("subprocess broken {e:?}"),
581+
};
573582
}
574583
}

0 commit comments

Comments
 (0)