The test read uptime with split_whitespace().nth(4), which assumed the column held a single token. That held only because the test measures about a second of uptime; once the formatter emits two tokens above a minute, raising the sleep would have shifted every later column while the assertion kept passing. Call the list RPC directly and assert on ServerSummary::uptime_secs. The daemon produces that value and the test only reads it, so the assertion no longer depends on a layout the project wrote itself. Mutation-proved: replacing the handler's elapsed().as_secs() with 0 fails the test on uptime_secs: Some(0). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D9BWMXKKNpid7XM6oFbyYq
38 lines
1.0 KiB
Rust
38 lines
1.0 KiB
Rust
mod common;
|
|
use common::*;
|
|
use xy_protocol::ServerState;
|
|
|
|
#[tokio::test]
|
|
async fn uptime_grows_while_a_server_stays_running() {
|
|
let xy = xy_bin();
|
|
let sleeper = sleep_server_bin();
|
|
let mut h = Harness::new();
|
|
h.write_server("alpha", sleeper.to_str().unwrap(), 19_101, "always");
|
|
h.start_daemon(&xy).await;
|
|
|
|
for _ in 0..40 {
|
|
let rows = h.list_rpc().await;
|
|
if rows
|
|
.iter()
|
|
.any(|r| r.name == "alpha" && r.state == ServerState::Running)
|
|
{
|
|
break;
|
|
}
|
|
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
|
}
|
|
|
|
tokio::time::sleep(std::time::Duration::from_millis(1_200)).await;
|
|
|
|
let rows = h.list_rpc().await;
|
|
|
|
let alpha = rows
|
|
.iter()
|
|
.find(|r| r.name == "alpha")
|
|
.unwrap_or_else(|| panic!("no alpha row in: {rows:?}"));
|
|
|
|
assert!(
|
|
alpha.uptime_secs.is_some_and(|secs| secs >= 1),
|
|
"a server running for over a second must report at least 1s of uptime; row: {alpha:?}"
|
|
);
|
|
}
|