Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/holger

agent/cli/tests/integration_nexus_bench_twin.rs

//! Downscaled correctness twin of the `holger.nexus_load` Bencher.
//!
//! Bench:  xtask/examples/nornir-bench.rs :: NexusLoad ("holger.nexus_load")
//! Ported from: integration_nexus_load.rs::test_nexus_load_with_real_artifacts
//!
//! This is the FAST, small-scale correctness check: it exercises the exact same
//! `holger_bench_scenarios::nexus::nexus_load` workload the full-scale bench
//! runs, but at a tiny `Scale` (few entries, 1s loop). The full-scale MB/s /
//! ops/s measurement lives in the bench so it lands in `bench_history`.
//!
//! ## Fixture gate (NOT `--heavy`)
//!
//! The Sonatype Nexus 3 testcontainer is a *fixture gate*, not heavy load: the
//! scenario tries to boot/connect and, when Docker/Podman is unavailable,
//! returns an `is_skip` error. This twin treats that as a recorded SKIP (the
//! test still passes) — it only asserts real numbers when a container is
//! actually present. So it is a NORMAL (non-`--ignored`) test.

use holger_bench_scenarios::{nexus, Scale};

use traits::test_support::fstatus;

/// Tiny scale for the twin: a handful of entries, a 1s loop.
fn twin_scale() -> Scale {
    Scale {
        entries: 16,
        bench_secs: 1,
        threads_mt: 2,
        // entry-driven twin bench (not byte-budgeted)
        target_bytes: None,
    }
}

// Multi-thread runtime is REQUIRED: `nexus_load` now stands up an in-process
// Holger HTTP gateway and drives it with a blocking GET pool; on a single-thread
// runtime the pool would starve the gateway's accept loop. Mirrors xtask's
// multi-thread `rt()`.
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[ignore = "heavy: needs Docker/Nexus container (container = heavy; fixture-gated, runs under --heavy)"]
async fn test_nexus_load_twin_small_scale() {
    let scale = twin_scale();
    match nexus::nexus_load(&scale).await {
        Ok(o) => {
            // Container present → assert the workload produced real numbers.
            assert_eq!(
                o.concurrency, scale.threads_mt,
                "concurrency must reflect scale"
            );
            assert!(o.holger_files > 0, "Holger archive must contain files");
            assert!(
                o.ops_per_sec > 0.0,
                "Holger must serve at least one op/sec over HTTP"
            );
            // Head-to-head: both served over HTTP, like-for-like.
            assert!(
                o.holger_served_mbs > 0.0,
                "Holger served MB/s must be positive"
            );
            assert!(
                o.nexus_served_mbs >= 0.0,
                "Nexus served MB/s must be non-negative"
            );
            // Internal ceiling is still produced (Holger-vs-Holger only).
            assert!(
                o.holger_inprocess_read_ceiling_mbs > 0.0,
                "in-process read ceiling must be positive"
            );
            assert!(o.elapsed_ms > 0.0, "elapsed must be positive");
            fstatus(
                "agent-bench",
                "nexus_load_twin",
                true,
                &format!(
                    "served: holger={:.1} MB/s nexus={:.1} MB/s ops/s={:.0} | \
                     inprocess_ceiling={:.1} MB/s files={}",
                    o.holger_served_mbs,
                    o.nexus_served_mbs,
                    o.ops_per_sec,
                    o.holger_inprocess_read_ceiling_mbs,
                    o.holger_files
                ),
            );
        }
        Err(e) => {
            // Fixture gate: no Docker/Nexus → recorded skip, NOT a failure.
            assert!(
                nexus::is_skip(&e),
                "non-skip error from nexus_load twin: {e:#}"
            );
            eprintln!("nexus_load twin skipped (fixture gate): {e}");
            fstatus(
                "agent-bench",
                "nexus_load_twin",
                true,
                &format!("skipped: {e}"),
            );
        }
    }
}