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.
135 lines
5.3 KiB
Rust
135 lines
5.3 KiB
Rust
//! Soak: mixed requests with pressure flips keep threads, descriptors and memory flat.
|
|
|
|
use crate::harness::{Stack, request, usage};
|
|
use leleka_backend_api::ErrorCode;
|
|
use leleka_backend_api::scripted::Script;
|
|
use leleka_memory::RealProc;
|
|
use leleka_memory::census::{Census, Tolerances, check_flat};
|
|
use std::time::Duration;
|
|
|
|
/// Deterministic mix without a random-number dependency.
|
|
fn pick(i: u64) -> u64 {
|
|
i.wrapping_mul(6_364_136_223_846_793_005)
|
|
.wrapping_add(1_442_695_040_888_963_407)
|
|
>> 33
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn soak_mixed_requests_with_pressure_flips_keep_threads_descriptors_and_memory_flat() {
|
|
let stack = Stack::start("mg-soak").await;
|
|
let total = 600u64;
|
|
let warmup = 20usize;
|
|
let mut series: Vec<Census> = Vec::new();
|
|
let (mut served, mut refused, mut abandoned, mut failed) = (0u64, 0u64, 0u64, 0u64);
|
|
for i in 0..total {
|
|
// the pressure level flips: reject for 12 of every 60 requests, shed for 12 more
|
|
let phase = i % 60;
|
|
let level = if phase >= 48 {
|
|
"reject"
|
|
} else if phase >= 36 {
|
|
"shed"
|
|
} else {
|
|
"normal"
|
|
};
|
|
if phase == 0 || phase == 36 || phase == 48 {
|
|
stack.set_level(level).await;
|
|
}
|
|
if level == "reject" {
|
|
// every kind of request is refused up front and never reaches the engine
|
|
let r = stack.post(&request(pick(i).is_multiple_of(2))).await;
|
|
assert_eq!(r.status().as_u16(), 503, "request {i}");
|
|
assert!(r.headers().get("retry-after").is_some());
|
|
let _ = r.bytes().await.unwrap();
|
|
refused += 1;
|
|
} else {
|
|
match pick(i) % 5 {
|
|
0 | 1 => {
|
|
stack
|
|
.engine
|
|
.push(Script::stop_with(&["ok ", "done"], usage()));
|
|
let r = stack.post(&request(false)).await;
|
|
assert_eq!(r.status().as_u16(), 200, "request {i}");
|
|
let _ = r.bytes().await.unwrap();
|
|
served += 1;
|
|
}
|
|
2 => {
|
|
stack
|
|
.engine
|
|
.push(Script::stop_with(&["ok ", "done"], usage()));
|
|
let r = stack.post(&request(true)).await;
|
|
assert_eq!(r.status().as_u16(), 200, "request {i}");
|
|
let text = r.text().await.unwrap();
|
|
assert!(text.contains("response.completed"), "request {i}: {text}");
|
|
served += 1;
|
|
}
|
|
3 => {
|
|
// the client walks away mid-stream
|
|
stack.engine.push(Script::hanging_after(&["start"]));
|
|
let mut r = stack.post(&request(true)).await;
|
|
assert_eq!(r.status().as_u16(), 200, "request {i}");
|
|
let mut seen = String::new();
|
|
while !seen.contains("response.output_text.delta") {
|
|
match tokio::time::timeout(Duration::from_secs(10), r.chunk())
|
|
.await
|
|
.unwrap()
|
|
.unwrap()
|
|
{
|
|
Some(chunk) => seen.push_str(&String::from_utf8_lossy(&chunk)),
|
|
None => break,
|
|
}
|
|
}
|
|
drop(r);
|
|
tokio::time::timeout(Duration::from_secs(10), async {
|
|
while stack.engine.is_generating() {
|
|
tokio::time::sleep(Duration::from_millis(2)).await;
|
|
}
|
|
})
|
|
.await
|
|
.expect("an abandoned stream was never cancelled in the engine");
|
|
abandoned += 1;
|
|
}
|
|
_ => {
|
|
// an engine-side failure: the request ends as a failure, the worker lives on
|
|
stack.engine.push(Script::failing_after(
|
|
&["a"],
|
|
ErrorCode::Internal,
|
|
"scripted failure",
|
|
));
|
|
let r = stack.post(&request(false)).await;
|
|
let status = r.status().as_u16();
|
|
assert!(status == 502 || status == 503, "request {i}: {status}");
|
|
let _ = r.bytes().await.unwrap();
|
|
failed += 1;
|
|
}
|
|
}
|
|
}
|
|
if i % 5 == 4 {
|
|
series.push(Census::take(&RealProc));
|
|
}
|
|
}
|
|
// drain: the engine ends idle, nothing queued
|
|
tokio::time::timeout(Duration::from_secs(10), async {
|
|
while stack.engine.is_generating() {
|
|
tokio::time::sleep(Duration::from_millis(5)).await;
|
|
}
|
|
})
|
|
.await
|
|
.expect("the engine never went idle");
|
|
let tolerances = Tolerances {
|
|
rss: 96 << 20,
|
|
threads: 3,
|
|
fds: 6,
|
|
..Tolerances::default()
|
|
};
|
|
let flat = check_flat(&series, warmup, &tolerances);
|
|
eprintln!(
|
|
"soak: served={served} refused={refused} abandoned={abandoned} failed={failed}\n{flat}"
|
|
);
|
|
assert!(
|
|
served > 100 && refused > 20 && abandoned > 20,
|
|
"the mix did not exercise every path"
|
|
);
|
|
assert!(flat.ok, "{flat}");
|
|
stack.finish().await;
|
|
}
|