Tests become directory modules named after what they test, with a shared fixtures/harness module:
control-plane/src/{responses,ggml_bridge,gguf_f32_stream,prepare_preview}/tests/, desktop-core/src/runtime_rpc/tests/;
integration targets become tests/<name>/main.rs plus topic modules and a harness (backend_worker_http, vision_http,
memory_gate_http, tool_corpus, mcp_hub, api_over_runtime, runtime_gateway_sdet, native_tools_sdet,
native_tools_retry_sdet, managed_worker, gateway); target names are unchanged. Sources: leleka-inference.rs becomes
src/bin/leleka-inference/ (main.rs plus one module per operator option group), the cp_replay example becomes
examples/cp_replay/, and the tonic service impl of runtime_rpc delegates to session_rpc, model_rpc and generate_rpc
(bodies unchanged). impl_* modules are renamed after what they hold (base_provenance, count_tokens, manifest_fetch,
fetcher, record, capture, in_flight, tool_policy, tool_plan, server). The self-spawning tests that name themselves
(credential_child, the managed worker fixture) use the new module path or stay at the target root.
Test ids: 543 before and after in both crates (strata-control, strata-desktop-core, --all-targets), 0 missing, 0 new,
0 outcome changes; 241 ids differ only in the module path. Warnings in the two crates: 0 before and after.
Counts (strata-control / strata-desktop-core): oversize files 19 -> 0 (13 + 6). Functions over 30 lines, complexity 10,
nesting 4, wide lines, prod: 187/135/17/199 -> 187/135/17/196 and 81/59/6/54 -> 81/59/6/54; test: 214/17/30/133 ->
214/17/30/133 and 65/3/3/30 -> 65/3/3/27. The 211 functions that moved verbatim are in limits-allowlist.json (owner
STRA-338) because the diff gate treats a moved function as added; the entries fall as the functions are shortened.
185 lines
5.8 KiB
Rust
185 lines
5.8 KiB
Rust
//! The owned worker over gRPC: start, stop, health and unexpected exit.
|
|
|
|
use crate::harness::{OUTPUT, TOKEN, command, profile, remote_finish, req, serve};
|
|
use std::time::Duration;
|
|
use strata_desktop_core::managed_worker::Manager;
|
|
use strata_desktop_core::node::proto::*;
|
|
use strata_desktop_core::node::{self};
|
|
use tokio::net::TcpListener;
|
|
|
|
async fn finish(m: &Manager, c: WorkerCommand) -> WorkerOperation {
|
|
let id = c.operation_id.clone();
|
|
m.submit(c).unwrap();
|
|
tokio::time::timeout(Duration::from_secs(5), async {
|
|
loop {
|
|
let s = m.operation(&id).unwrap();
|
|
if s.status == "succeeded" || s.status == "failed" {
|
|
break s;
|
|
}
|
|
tokio::time::sleep(Duration::from_millis(10)).await;
|
|
}
|
|
})
|
|
.await
|
|
.unwrap()
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn grpc_owned_start_stop_and_exact_response() {
|
|
let server = serve(profile("test").await).await;
|
|
let mut c = node::connect(server.address).await.unwrap();
|
|
assert_eq!(
|
|
c.worker_status(Empty {}).await.unwrap_err().code(),
|
|
tonic::Code::Unauthenticated
|
|
);
|
|
assert_eq!(
|
|
c.worker_status(req(Empty {}))
|
|
.await
|
|
.unwrap()
|
|
.into_inner()
|
|
.phase,
|
|
"stopped"
|
|
);
|
|
let input = ResponseRequest {
|
|
json: br#"{"model":"fixture","input":"synthetic","stream":false}"#.to_vec(),
|
|
};
|
|
assert_eq!(
|
|
c.respond(req(input.clone())).await.unwrap_err().code(),
|
|
tonic::Code::Unavailable
|
|
);
|
|
let mut stale = command(1, 0);
|
|
stale.expected_epoch = "old-epoch".into();
|
|
assert_eq!(
|
|
c.control_worker(req(stale)).await.unwrap_err().code(),
|
|
tonic::Code::FailedPrecondition
|
|
);
|
|
assert_eq!(
|
|
c.worker_status(req(Empty {}))
|
|
.await
|
|
.unwrap()
|
|
.into_inner()
|
|
.phase,
|
|
"stopped"
|
|
);
|
|
let op = command(1, 0);
|
|
assert_eq!(remote_finish(&mut c, op.clone()).await.status, "succeeded");
|
|
let state = c.worker_status(req(Empty {})).await.unwrap().into_inner();
|
|
assert_eq!(state.phase, "ready");
|
|
assert_ne!(state.pid, 0);
|
|
// Same operation ID survives transport disconnect without spawning twice.
|
|
drop(c);
|
|
let mut c = node::connect(server.address).await.unwrap();
|
|
assert_eq!(
|
|
c.control_worker(req(op.clone()))
|
|
.await
|
|
.unwrap()
|
|
.into_inner()
|
|
.status,
|
|
"succeeded"
|
|
);
|
|
assert_eq!(
|
|
c.worker_status(req(Empty {}))
|
|
.await
|
|
.unwrap()
|
|
.into_inner()
|
|
.pid,
|
|
state.pid
|
|
);
|
|
let mut conflict = op;
|
|
conflict.action = 2;
|
|
assert_eq!(
|
|
c.control_worker(req(conflict)).await.unwrap_err().code(),
|
|
tonic::Code::AlreadyExists
|
|
);
|
|
let mut frames = c.respond(req(input.clone())).await.unwrap().into_inner();
|
|
let mut data = vec![];
|
|
let mut end = false;
|
|
while let Some(frame) = frames.message().await.unwrap() {
|
|
match frame.payload.unwrap() {
|
|
response_frame::Payload::Data(b) => data.extend(b),
|
|
response_frame::Payload::End(_) => end = true,
|
|
response_frame::Payload::Headers(h) => assert_eq!(h.status, 200),
|
|
}
|
|
}
|
|
assert_eq!(data, OUTPUT.as_bytes());
|
|
assert!(end);
|
|
assert_eq!(
|
|
remote_finish(&mut c, command(2, 1000)).await.status,
|
|
"succeeded"
|
|
);
|
|
assert_eq!(
|
|
c.worker_status(req(Empty {}))
|
|
.await
|
|
.unwrap()
|
|
.into_inner()
|
|
.phase,
|
|
"stopped"
|
|
);
|
|
assert_eq!(
|
|
c.respond(req(input)).await.unwrap_err().code(),
|
|
tonic::Code::Unavailable
|
|
);
|
|
assert_eq!(
|
|
remote_finish(&mut c, command(1, 0)).await.status,
|
|
"succeeded"
|
|
);
|
|
let mut old = c
|
|
.respond(req(ResponseRequest {
|
|
json:
|
|
br#"{"model":"fixture","input":"synthetic","previous_response_id":"resp_fixture"}"#
|
|
.to_vec(),
|
|
}))
|
|
.await
|
|
.unwrap()
|
|
.into_inner();
|
|
assert!(matches!(
|
|
old.message().await.unwrap().unwrap().payload,
|
|
Some(response_frame::Payload::Headers(ResponseHeaders {
|
|
status: 409,
|
|
..
|
|
}))
|
|
));
|
|
drop(old);
|
|
assert_eq!(
|
|
remote_finish(&mut c, command(2, 1000)).await.status,
|
|
"succeeded"
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn wrong_health_and_occupied_endpoint_fail_closed() {
|
|
let mut p = profile("wrong").await;
|
|
p.startup_timeout_ms = 300;
|
|
let g = p.gateway(TOKEN.into()).unwrap();
|
|
let m = Manager::new(p, g).unwrap();
|
|
assert_eq!(finish(&m, command(1, 0)).await.reason, "startup_timeout");
|
|
assert_eq!(m.state().pid, 0);
|
|
let p = profile("test").await;
|
|
let held = TcpListener::bind(p.endpoint).await.unwrap();
|
|
let m = Manager::new(p.clone(), p.gateway(TOKEN.into()).unwrap()).unwrap();
|
|
assert_eq!(finish(&m, command(1, 0)).await.reason, "endpoint_occupied");
|
|
assert_eq!(m.state().pid, 0);
|
|
assert!(
|
|
tokio::net::TcpStream::connect(held.local_addr().unwrap())
|
|
.await
|
|
.is_ok()
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn unexpected_child_exit_closes_admission_and_can_restart() {
|
|
let p = profile("test").await;
|
|
let m = Manager::new(p.clone(), p.gateway(TOKEN.into()).unwrap()).unwrap();
|
|
assert_eq!(finish(&m, command(1, 0)).await.status, "succeeded");
|
|
let _ = reqwest::get(format!("http://{}/exit", p.endpoint)).await;
|
|
tokio::time::timeout(Duration::from_secs(2), async {
|
|
while m.state().phase != "failed" {
|
|
tokio::time::sleep(Duration::from_millis(20)).await;
|
|
}
|
|
})
|
|
.await
|
|
.unwrap();
|
|
assert_eq!(m.state().reason, "worker_exited");
|
|
assert_eq!(finish(&m, command(1, 0)).await.status, "succeeded");
|
|
assert_eq!(finish(&m, command(2, 0)).await.status, "succeeded");
|
|
}
|