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

nordisk/knut

crates/graphar-falkordb/tests/testmatrix_wiring.rs

//! Wiring proof for graphar-falkordb's `functional_status` test-matrix surface
//! (the newest feature: the UNWIND-batched Cypher loader reports each vertex /
//! edge bulk-insert's health into the nornir matrix). The live call sites sit
//! inside async `FalkorDbLoader` methods that need a FalkorDB backend, so —
//! mirroring graphar-flight — this exercises the crate's public
//! `functional_status` wrapper directly (the same forwarder those loader
//! methods call) and asserts on the REAL emitted rows. Offline, in-process.
//!
//! One test per build (single test per binary → no race on the process-global
//! functional buffer `--features testmatrix` records into):
//!   * default build → the wrapper is a compiled-out no-op; assert it links.
//!   * `--features testmatrix` → assert the wrapper records the two loader
//!     surfaces with the correct green/red status mapping.

/// Default build: `testmatrix` OFF → `functional_status` is an inlined no-op.
#[cfg(not(feature = "testmatrix"))]
#[test]
fn functional_status_is_a_linked_noop() {
    graphar_falkordb::functional_status(
        "graphar-falkordb/loader",
        "insert_vertices",
        true,
        "3 vertices as :Person",
    );
    graphar_falkordb::functional_status(
        "graphar-falkordb/loader",
        "insert_edges",
        false,
        "empty batches",
    );
}

/// `--features testmatrix`: the wrapper must forward each loader surface's
/// outcome into the matrix with the right status mapping — mirroring the real
/// `insert_vertices_multi` (insert_vertices) and `insert_edges_keyed`
/// (insert_edges) call sites.
#[cfg(feature = "testmatrix")]
#[test]
fn wrapper_forwards_loader_surface_outcomes() {
    use nornir_testmatrix::{drain_functional_rows, status};

    let _ = drain_functional_rows();

    // vertex bulk-insert → succeeded (green).
    graphar_falkordb::functional_status(
        "graphar-falkordb/loader",
        "insert_vertices",
        true,
        "3 vertices as :Person",
    );
    // edge bulk-insert → failed (red).
    graphar_falkordb::functional_status(
        "graphar-falkordb/loader",
        "insert_edges",
        false,
        "empty batches",
    );
    // native GRAPH.BULK fast-lane → succeeded (green).
    graphar_falkordb::functional_status(
        "graphar-falkordb/loader",
        "bulk_insert",
        true,
        "3 nodes + 2 relations via GRAPH.BULK",
    );
    // streamed/appendable GRAPH.BULK → succeeded (green) — the surface
    // knut-popviz's auto-selected bulk fast lane drives (`bulk_insert_streamed`).
    graphar_falkordb::functional_status(
        "graphar-falkordb/loader",
        "bulk_insert_streamed",
        true,
        "6060 nodes + 5510 relations via streamed GRAPH.BULK",
    );

    let rows = drain_functional_rows();

    let v = rows
        .iter()
        .find(|r| r.suite == "graphar-falkordb/loader" && r.test_name == "insert_vertices")
        .unwrap_or_else(|| panic!("vertex-load surface must record; got {rows:?}"));
    assert!(
        status::is_green(&v.status),
        "a successful vertex load is GREEN: {v:?}"
    );
    assert_eq!(v.aspect, "functional");
    assert_eq!(v.metric, 0.0);
    assert_eq!(
        v.message, "3 vertices as :Person",
        "detail carries the load summary"
    );

    let e = rows
        .iter()
        .find(|r| r.suite == "graphar-falkordb/loader" && r.test_name == "insert_edges")
        .unwrap_or_else(|| panic!("edge-load surface must record; got {rows:?}"));
    assert!(
        status::is_red(&e.status),
        "a failed edge load is RED: {e:?}"
    );
    assert_eq!(e.metric, 1.0, "red rows carry metric 1.0");
    assert_eq!(
        e.message, "empty batches",
        "detail carries the failure reason"
    );

    // The native GRAPH.BULK fast-lane surface reports its health the same way
    // (the forwarder the async `bulk_insert` method calls on completion).
    let b = rows
        .iter()
        .find(|r| r.suite == "graphar-falkordb/loader" && r.test_name == "bulk_insert")
        .unwrap_or_else(|| panic!("bulk_insert surface must record; got {rows:?}"));
    assert!(
        status::is_green(&b.status),
        "a successful GRAPH.BULK load is GREEN: {b:?}"
    );
    assert_eq!(b.message, "3 nodes + 2 relations via GRAPH.BULK");

    // The streamed/appendable GRAPH.BULK surface (popviz's auto-selected lane).
    let bs = rows
        .iter()
        .find(|r| r.suite == "graphar-falkordb/loader" && r.test_name == "bulk_insert_streamed")
        .unwrap_or_else(|| panic!("bulk_insert_streamed surface must record; got {rows:?}"));
    assert!(
        status::is_green(&bs.status),
        "a successful streamed load is GREEN: {bs:?}"
    );
    assert_eq!(
        bs.message,
        "6060 nodes + 5510 relations via streamed GRAPH.BULK"
    );
}