STRA-338 size-fn: leleka-deploy: remaining e2e and unit test helpers
This commit is contained in:
@@ -192,7 +192,11 @@ pub(super) fn report_logs_and_requests(paths: &Paths, config: &RunConfig, health
|
||||
paths.logs().join("requests.log").display()
|
||||
),
|
||||
}
|
||||
let recent = crate::logview::recent_requests(&paths.logs(), 200);
|
||||
note_failed_requests(health, &crate::logview::recent_requests(&paths.logs(), 200));
|
||||
}
|
||||
|
||||
/// A note when a fifth or more of the last requests (at least ten were made) failed or were rejected.
|
||||
fn note_failed_requests(health: &mut Health, recent: &[Value]) {
|
||||
let failed = recent
|
||||
.iter()
|
||||
.filter(|r| matches!(r["fin"].as_str(), Some("error" | "rejected")))
|
||||
|
||||
@@ -112,22 +112,7 @@ fn a_local_file_is_installed_offline_and_a_wrong_one_is_refused() {
|
||||
let mut never = |_: &str, _: &Path| -> Result<(), String> {
|
||||
panic!("offline: no download may be attempted")
|
||||
};
|
||||
let refused = provision(
|
||||
&Request {
|
||||
dest: &dest,
|
||||
expected: &digest,
|
||||
local: Some(&bad),
|
||||
embedded: None,
|
||||
sources: &["https://x.test/p"],
|
||||
},
|
||||
&mut never,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
refused.contains("only the pinned upstream table"),
|
||||
"{refused}"
|
||||
);
|
||||
assert!(!dest.exists());
|
||||
check_wrong_local_file_is_refused(&dest, &bad, &digest, &mut never);
|
||||
let outcome = provision(
|
||||
&Request {
|
||||
dest: &dest,
|
||||
@@ -147,19 +132,51 @@ fn a_local_file_is_installed_offline_and_a_wrong_one_is_refused() {
|
||||
}
|
||||
));
|
||||
assert_eq!(std::fs::read(&dest).unwrap(), FIXTURE);
|
||||
check_missing_local_file(&dir, &digest, &mut never);
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
fn check_wrong_local_file_is_refused(
|
||||
dest: &Path,
|
||||
bad: &Path,
|
||||
digest: &str,
|
||||
never: &mut impl FnMut(&str, &Path) -> Result<(), String>,
|
||||
) {
|
||||
let refused = provision(
|
||||
&Request {
|
||||
dest,
|
||||
expected: digest,
|
||||
local: Some(bad),
|
||||
embedded: None,
|
||||
sources: &["https://x.test/p"],
|
||||
},
|
||||
never,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
refused.contains("only the pinned upstream table"),
|
||||
"{refused}"
|
||||
);
|
||||
assert!(!dest.exists());
|
||||
}
|
||||
|
||||
fn check_missing_local_file(
|
||||
dir: &Path,
|
||||
digest: &str,
|
||||
never: &mut impl FnMut(&str, &Path) -> Result<(), String>,
|
||||
) {
|
||||
let missing = provision(
|
||||
&Request {
|
||||
dest: &dir.join("other.bin"),
|
||||
expected: &digest,
|
||||
expected: digest,
|
||||
local: Some(&dir.join("nope.bin")),
|
||||
embedded: None,
|
||||
sources: &[],
|
||||
},
|
||||
&mut never,
|
||||
never,
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(missing.contains("--expert-profile-file"), "{missing}");
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -143,18 +143,22 @@ impl Watchdog {
|
||||
self.not_ready_since = None;
|
||||
match active_s {
|
||||
Some(seconds) if seconds >= self.limits.max_request.as_secs_f64() => {
|
||||
Verdict::RestartEngine(format!(
|
||||
concat!(
|
||||
"a request has been active for {seconds:.0} s, beyond the longest allowed ({} s): ",
|
||||
"the engine makes no progress"
|
||||
),
|
||||
self.limits.max_request.as_secs(),
|
||||
seconds = seconds
|
||||
))
|
||||
Verdict::RestartEngine(self.stall_reason(seconds))
|
||||
}
|
||||
_ => Verdict::Healthy,
|
||||
}
|
||||
}
|
||||
|
||||
fn stall_reason(&self, seconds: f64) -> String {
|
||||
format!(
|
||||
concat!(
|
||||
"a request has been active for {seconds:.0} s, beyond the longest allowed ({} s): ",
|
||||
"the engine makes no progress"
|
||||
),
|
||||
self.limits.max_request.as_secs(),
|
||||
seconds = seconds
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -12,7 +12,13 @@ fn dry_run(fixture: &Fixture, bin: &std::path::Path, extra: &[&str]) -> std::pro
|
||||
Process::new(LELEKA)
|
||||
.args(["up", "--dry-run"])
|
||||
.args(extra)
|
||||
.args(["--profile", "rtx5090-32g", "--mode", "foreground", "--assets"])
|
||||
.args([
|
||||
"--profile",
|
||||
"rtx5090-32g",
|
||||
"--mode",
|
||||
"foreground",
|
||||
"--assets",
|
||||
])
|
||||
.arg(&fixture.dirs.assets)
|
||||
.arg("--state-dir")
|
||||
.arg(&fixture.dirs.state)
|
||||
|
||||
@@ -7,7 +7,8 @@ use std::{
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
/// A fixture with the fakes, the file-backed profile written as state and an archive stand-in; with the path of the config.
|
||||
/// A fixture with the fakes, the file-backed profile written as state and an archive stand-in; with the path of the
|
||||
/// config.
|
||||
fn file_service(name: &str) -> (Fixture, std::path::PathBuf) {
|
||||
let fixture = Fixture::new(name);
|
||||
fixture.install_fake_binaries(&fixture.dirs.prefix.join("bin"));
|
||||
|
||||
@@ -20,7 +20,8 @@ async fn up_installs_the_expert_profile_offline_and_reports_it() {
|
||||
scene.the_opt_out_is_recorded_and_reported().await;
|
||||
}
|
||||
|
||||
/// The offline scenario: a profile that pins the digest of a small fixture, so that the flow runs without the real table.
|
||||
/// The offline scenario: a profile that pins the digest of a small fixture, so that the flow runs without the real
|
||||
/// table.
|
||||
struct Scene {
|
||||
fixture: Fixture,
|
||||
bin_src: std::path::PathBuf,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
//! Reconfigure flows against the fake runtime: planning, persisting, restart and rollback.
|
||||
|
||||
use crate::harness::*;
|
||||
use leleka_deploy::config::RunConfig;
|
||||
use leleka_deploy::profile::{KarSource, Profile};
|
||||
use leleka_deploy::reconfigure::{Outcome, Request, State, read_outcome, write_request};
|
||||
use leleka_deploy::resources::Preset;
|
||||
use leleka_deploy::config::RunConfig;
|
||||
use serde_json::json;
|
||||
use std::{
|
||||
fs,
|
||||
@@ -38,6 +38,13 @@ fn a_new_budget_restarts_only_the_engine_with_the_same_sealed_archive() {
|
||||
);
|
||||
assert!(!outcome.persisted);
|
||||
assert_eq!(outcome.effective.as_ref().unwrap()["gpu_budget_gib"], 2.0);
|
||||
check_only_the_engine_was_replaced(fixture, (engine, gateway, api));
|
||||
check_new_engine_arguments(&service);
|
||||
check_not_persisted_and_same_budget_is_a_noop(&service, &before);
|
||||
service.stop();
|
||||
}
|
||||
|
||||
fn check_only_the_engine_was_replaced(fixture: &Fixture, (engine, gateway, api): (u64, u64, u64)) {
|
||||
let after = fixture.wait_for("ready again", Duration::from_secs(60), |s| {
|
||||
s["phase"] == "ready"
|
||||
});
|
||||
@@ -62,9 +69,6 @@ fn a_new_budget_restarts_only_the_engine_with_the_same_sealed_archive() {
|
||||
"a planned restart is not a crash"
|
||||
);
|
||||
assert_eq!(fixture.http_status("/ready"), 200);
|
||||
check_new_engine_arguments(&service);
|
||||
check_not_persisted_and_same_budget_is_a_noop(&service, &before);
|
||||
service.stop();
|
||||
}
|
||||
|
||||
/// The second engine has the new budget and is handed the first one's verified sealed descriptor.
|
||||
@@ -172,6 +176,11 @@ fn check_persisted_numbers_survive(service: &Service, gateway: u64, api: u64, co
|
||||
assert_ne!(after["api_pid"].as_u64().unwrap(), api);
|
||||
assert_eq!(after["gateway_pid"].as_u64().unwrap(), gateway);
|
||||
assert_eq!(fixture.http_status("/ready"), 200);
|
||||
check_crash_restart_keeps_the_new_numbers(service, &after);
|
||||
}
|
||||
|
||||
fn check_crash_restart_keeps_the_new_numbers(service: &Service, after: &serde_json::Value) {
|
||||
let fixture = &service.fixture;
|
||||
// a crash of the new engine restarts it with the new numbers, not the old ones
|
||||
signal(after["engine_pid"].as_u64().unwrap(), "KILL");
|
||||
let again = fixture.wait_for("crash restart", Duration::from_secs(60), |s| {
|
||||
@@ -305,6 +314,11 @@ fn check_failed_new_engine_restores_the_old_one(service: &Service, engine: u64)
|
||||
"{}",
|
||||
outcome.message
|
||||
);
|
||||
check_restored_engine(service, engine);
|
||||
}
|
||||
|
||||
fn check_restored_engine(service: &Service, engine: u64) {
|
||||
let fixture = &service.fixture;
|
||||
let restored = fixture.wait_for("restored", Duration::from_secs(60), |s| {
|
||||
s["phase"] == "ready"
|
||||
});
|
||||
|
||||
@@ -19,6 +19,8 @@ async fn up_is_idempotent_resumable_and_never_rotates_secrets() {
|
||||
reverify_forces_the_verification(&scene).await;
|
||||
}
|
||||
|
||||
type Options = leleka_deploy::cli::UpOptions;
|
||||
|
||||
/// The directories and fakes of one `up` scenario.
|
||||
struct Scene {
|
||||
fixture: Fixture,
|
||||
@@ -44,13 +46,13 @@ impl Scene {
|
||||
}
|
||||
}
|
||||
|
||||
fn options(&self, extra: &[&str]) -> leleka_deploy::cli::UpOptions {
|
||||
fn options(&self, extra: &[&str]) -> Options {
|
||||
up_options(&self.fixture, &self.bin_src, &self.cublas, &self.mtp, extra)
|
||||
}
|
||||
}
|
||||
|
||||
/// First run: everything is a todo, then everything exists. Returns the environment file it wrote.
|
||||
async fn first_run_builds_everything(scene: &Scene, opts: &leleka_deploy::cli::UpOptions) -> String {
|
||||
async fn first_run_builds_everything(scene: &Scene, opts: &Options) -> String {
|
||||
let paths = scene.fixture.dirs.paths();
|
||||
let ctx = healthy_context(opts);
|
||||
let fs0 = gather_fs(&ctx).await;
|
||||
@@ -79,7 +81,8 @@ async fn first_run_builds_everything(scene: &Scene, opts: &leleka_deploy::cli::U
|
||||
check_modes_config_and_calls(scene)
|
||||
}
|
||||
|
||||
/// Private environment file, read-only archive, the profile of the run and the tools called once. Returns the environment file.
|
||||
/// Private environment file, read-only archive, the profile of the run and the tools called once.
|
||||
/// Returns the environment file.
|
||||
fn check_modes_config_and_calls(scene: &Scene) -> String {
|
||||
let (fixture, paths) = (&scene.fixture, scene.fixture.dirs.paths());
|
||||
assert_eq!(
|
||||
@@ -111,7 +114,7 @@ fn check_modes_config_and_calls(scene: &Scene) -> String {
|
||||
}
|
||||
|
||||
/// Second run: the plan has nothing to do and no tool is invoked again.
|
||||
async fn second_run_does_nothing(scene: &Scene, opts: &leleka_deploy::cli::UpOptions, env_first: &str) {
|
||||
async fn second_run_does_nothing(scene: &Scene, opts: &Options, env_first: &str) {
|
||||
let (fixture, paths) = (&scene.fixture, scene.fixture.dirs.paths());
|
||||
let ctx = healthy_context(opts);
|
||||
let fs1 = gather_fs(&ctx).await;
|
||||
|
||||
Reference in New Issue
Block a user