Files
boxmaker/crates/bxctl/tests/admin_timeout.rs
T
kyleandClaude Opus 5.5 bb4d7c0919 bxctl: escape frame errors; say the outcome is unknown after a timeout
From the independent review of task 23. serde quotes a bad frame's text after
decoding, so a compromised peer could put escape sequences in it. A timed-out
admin request now says whether brokerd acted is unknown, since it may have.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-22 21:48:24 -07:00

43 lines
1.4 KiB
Rust

//! A `brokerd` that accepts and never answers does not hang `bxctl` (M3a review finding 9).
use std::os::unix::net::UnixListener;
use std::time::{Duration, Instant};
use bxctl::admin::{ADMIN_TIMEOUT, request_with_timeout};
use proto::{Empty, Message};
#[test]
fn the_default_is_thirty_seconds() {
assert_eq!(ADMIN_TIMEOUT, Duration::from_secs(30));
}
#[test]
fn a_silent_brokerd_is_an_error_after_the_timeout() {
let dir = std::env::temp_dir().join(format!("bx-admin-timeout-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let socket = dir.join("admin.sock");
let listener = UnixListener::bind(&socket).unwrap();
let held = std::thread::spawn(move || {
let (stream, _) = listener.accept().unwrap();
std::thread::sleep(Duration::from_millis(2_000));
drop(stream);
});
let started = Instant::now();
let got = request_with_timeout(
&socket,
Message::Approvals(Empty {}),
Duration::from_millis(200),
);
let took = started.elapsed();
let text = got.expect_err("a silent brokerd is an error").to_string();
assert!(
text.contains("whether it acted is unknown"),
"brokerd may have approved and run the call before going quiet: {text}"
);
assert!(took < Duration::from_millis(1_500), "waited {took:?}");
held.join().unwrap();
let _ = std::fs::remove_dir_all(&dir);
}