74 lines
2.0 KiB
Rust
74 lines
2.0 KiB
Rust
mod harness;
|
|
mod lifecycle;
|
|
mod stop_and_cli;
|
|
|
|
use crate::harness::OUTPUT;
|
|
use std::time::Duration;
|
|
use tokio::net::TcpListener;
|
|
|
|
fn fixture_router(model: String) -> axum::Router {
|
|
let health_model = if model == "wrong" {
|
|
"unexpected".to_string()
|
|
} else {
|
|
model.clone()
|
|
};
|
|
axum::Router::new()
|
|
.route(
|
|
"/health",
|
|
axum::routing::get(move || {
|
|
let model = health_model.clone();
|
|
async move { axum::Json(serde_json::json!({"status":"ok","loaded":true,"model":model})) }
|
|
}),
|
|
)
|
|
.route("/v1/responses", axum::routing::post(responses_route(model == "slow")))
|
|
.route("/exit", axum::routing::get(exit_route))
|
|
}
|
|
|
|
fn responses_route(slow: bool) -> axum::routing::MethodRouter {
|
|
if slow {
|
|
axum::routing::post(respond_slowly)
|
|
} else {
|
|
axum::routing::post(respond_at_once)
|
|
}
|
|
}
|
|
|
|
async fn respond_slowly() -> impl axum::response::IntoResponse {
|
|
tokio::time::sleep(Duration::from_millis(600)).await;
|
|
respond_at_once().await
|
|
}
|
|
|
|
async fn respond_at_once() -> impl axum::response::IntoResponse {
|
|
(
|
|
[(axum::http::header::CONTENT_TYPE, "application/json")],
|
|
OUTPUT,
|
|
)
|
|
}
|
|
|
|
async fn exit_route() -> &'static str {
|
|
std::process::exit(7);
|
|
#[allow(unreachable_code)]
|
|
"exited"
|
|
}
|
|
|
|
// Same Rust test executable becomes a real isolated backend child. No Python,
|
|
// GPU, model download, request capture or running user endpoint is involved.
|
|
#[test]
|
|
#[ignore]
|
|
fn fixture() {
|
|
let Ok(endpoint) = std::env::var("STRATA_WORKER_ENDPOINT") else {
|
|
return;
|
|
};
|
|
assert!(std::env::var("STRATA_NODE_TOKEN").is_err());
|
|
let model = std::env::var("STRATA_WORKER_MODEL").unwrap();
|
|
tokio::runtime::Builder::new_current_thread()
|
|
.enable_all()
|
|
.build()
|
|
.unwrap()
|
|
.block_on(async move {
|
|
let router = fixture_router(model);
|
|
axum::serve(TcpListener::bind(endpoint).await.unwrap(), router)
|
|
.await
|
|
.unwrap();
|
|
});
|
|
}
|