Skip to content

Commit 4276b38

Browse files
karthiknadigCopilot
andcommitted
test: measure broken-output shutdown after readiness (Refs #529)
Establish a bounded info exchange before closing the same stdout pipe, so startup is not charged to the unchanged one-second shutdown deadline. Explicitly terminate and bounded-join the readiness helper on setup failure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 94af1da commit 4276b38

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

‎crates/pet/tests/jsonrpc_server_test.rs‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,31 @@ fn truncated_input_exits_unsuccessfully_without_an_error_flood() {
585585
#[test]
586586
fn closed_output_exits_without_waiting_for_stdin_eof() {
587587
let mut fixture = ShutdownFixture::spawn();
588-
drop(fixture.child.stdout.take());
588+
let mut stdout = BufReader::new(fixture.child.stdout.take().unwrap());
589+
let (sender, receiver) = mpsc::sync_channel(1);
590+
let reader = thread::spawn(move || {
591+
let response = jsonrpc_client::read_message(&mut stdout);
592+
let _ = sender.send((stdout, response));
593+
});
594+
fixture.send(br#"{"jsonrpc":"2.0","id":"ready","method":"info"}"#);
595+
let (stdout, response) = match receiver.recv_timeout(Duration::from_secs(10)) {
596+
Ok(result) => result,
597+
Err(error) => {
598+
drop(receiver);
599+
fixture.child.stdin.take();
600+
let shutdown =
601+
jsonrpc_client::shutdown_fixture(&mut fixture.child, Duration::from_secs(4));
602+
let joined = jsonrpc_client::join_reader(reader, Duration::from_secs(4));
603+
panic!("server readiness failed: {error}; shutdown: {shutdown:?}; reader: {joined:?}");
604+
}
605+
};
606+
jsonrpc_client::join_reader(reader, Duration::from_secs(1)).unwrap();
607+
let response = response
608+
.unwrap()
609+
.expect("ready server must respond to info");
610+
assert_eq!(response["id"], "ready");
611+
drop(stdout);
612+
589613
let started = Instant::now();
590614
fixture.send(br#"{"jsonrpc":"2.0","id":1,"method":"info"}"#);
591615
let status = jsonrpc_client::wait_for_exit(&mut fixture.child, Duration::from_secs(1)).unwrap();

0 commit comments

Comments
 (0)