crates/nornir-build-thing/examples/probe_log_tail.rs
//! Probe (throwaway): does the container road lose a chatty container's stdout?
//! args: <image> <lines> <rounds> <pre-sleep seconds>
use nornir_build_thing::cargo_container::{
CargoContainerRunner, CargoRunRequest, DraupnirCargoRunner,
};
use std::time::Duration;
fn main() -> anyhow::Result<()> {
let image = std::env::args().nth(1).expect("image");
let n: usize = std::env::args().nth(2).unwrap_or_else(|| "900".into()).parse()?;
let rounds: usize = std::env::args().nth(3).unwrap_or_else(|| "8".into()).parse()?;
let pre: usize = std::env::args().nth(4).unwrap_or_else(|| "0".into()).parse()?;
let runner = DraupnirCargoRunner::new();
let mut lost = 0usize;
for r in 0..rounds {
let req = CargoRunRequest {
name: format!("logtail-{r}"),
image: image.clone(),
script: format!(
"sleep {pre}; i=0; while [ $i -lt {n} ]; do echo \"{{\\\"reason\\\":\\\"compiler-artifact\\\",\\\"n\\\":$i}}\"; i=$((i+1)); done; echo '{{\"reason\":\"LAST\"}}'\n"
),
binds: vec![],
timeout: Duration::from_secs(300),
network: false,
mem_limit_mb: 1024,
cpus: 2,
};
let out = runner.run(&req)?;
let got = out.stdout.len();
let last = out.stdout.iter().any(|l| l.contains("\"LAST\""));
if got != n + 1 || !last {
lost += 1;
println!(
"round {r}: LOST exit={:?} stdout_lines={got} (expected {}) LAST={last}",
out.exit_code,
n + 1
);
}
}
println!("rounds that LOST lines: {lost}/{rounds} (pre-sleep {pre}s, {n} lines)");
Ok(())
}