Files
boxmaker/crates/loopd/tests/broker_port_cap.rs
T
kyleandClaude Opus 5.5 2b3ae080b4 proto becomes bxcore, the one shared crate (M5b task 00)
Done the way the owner asked and the spike mapped: the crate and the
manifests renamed, then what the build reported fixed. Layers: 138
"proto unresolved" errors across 169 files; cargo fmt reordering
imports; six fixture paths built as strings in brokerd's and bxctl's
tests, which the compiler cannot see, and comments naming
crates/proto/; the crate-dependency check and its self-test. One more
the spike did not reach: a `\nproto =` key inside a printf format in
the self-test, which a word-boundary replacement skips because `n` and
`p` are both word characters.

make gate: gate: ok, 944 tests; no new entry in /tmp.

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

61 lines
1.9 KiB
Rust

//! After a pending frame, `BrokerPort` waits for `expires` plus its timeout, but never longer than
//! its cap, whatever `expires` says (M3a review finding 8). `brokerd` falls back to the largest
//! timestamp when `now + ttl_ms` does not fit, so a far `expires` is reachable by configuration.
#[path = "support/broker.rs"]
mod fake;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::{Duration, Instant};
use bxcore::{Timestamp, ToolResponse};
use fake::{broker, request, send};
use loopd::broker_port::{BrokerPort, MAX_PENDING_WAIT, UNAVAILABLE};
use loopd::tools::ToolPort;
#[test]
fn the_default_cap_is_a_day() {
assert_eq!(MAX_PENDING_WAIT, Duration::from_secs(24 * 60 * 60));
}
#[test]
fn a_pending_frame_with_the_largest_expiry_still_ends_at_the_cap() {
let (socket, broker) = broker(|stream, request| {
let pending = ToolResponse::PendingApproval {
approval: 7,
expires: Timestamp::MAX,
};
send(stream, request.id, false, pending);
thread::sleep(Duration::from_millis(1_500));
});
let lines = Arc::new(Mutex::new(Vec::new()));
let sink = lines.clone();
let port = BrokerPort::with_log(
socket,
Duration::from_millis(100),
Box::new(move |line| sink.lock().unwrap().push(line.to_string())),
)
.with_pending_cap(Duration::from_millis(200));
let started = Instant::now();
let answer = port.call(&request(), &mut |_| {});
let took = started.elapsed();
assert_eq!(
answer,
ToolResponse::Failed {
message: UNAVAILABLE.to_string()
}
);
assert!(
took >= Duration::from_millis(250),
"cap plus timeout: {took:?}"
);
assert!(
took < Duration::from_millis(1_200),
"gave up late: {took:?}"
);
assert_eq!(lines.lock().unwrap().len(), 1);
broker.join().unwrap();
}