Initialize repository snapshot
This commit is contained in:
76
vaultmesh-mesh/tests/metrics_integration.rs
Normal file
76
vaultmesh-mesh/tests/metrics_integration.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
//! Integration test: Mesh operations update observability metrics
|
||||
//!
|
||||
//! Run with:
|
||||
//! cargo test -p vaultmesh-mesh --features metrics --test metrics_integration
|
||||
//!
|
||||
#![cfg(feature = "metrics")]
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::net::TcpListener;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use tempfile::TempDir;
|
||||
use tokio::time::sleep;
|
||||
|
||||
use vaultmesh_mesh::{MeshEngine, NodeType};
|
||||
use vaultmesh_observability::ObservabilityEngine;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_mesh_operations_update_observability_metrics() {
|
||||
// Temporary dir for mesh persistence
|
||||
let tmp = TempDir::new().expect("tempdir");
|
||||
|
||||
// Dynamic port allocation - bind to port 0 to get an available port
|
||||
let listener = TcpListener::bind("127.0.0.1:0").expect("bind to port 0");
|
||||
let addr = listener.local_addr().expect("get local addr");
|
||||
drop(listener); // Release so ObservabilityEngine can bind
|
||||
|
||||
// Start observability engine on the dynamically assigned port
|
||||
let obs = Arc::new(ObservabilityEngine::new());
|
||||
obs.clone()
|
||||
.serve(&addr)
|
||||
.await
|
||||
.expect("observability serve failed");
|
||||
|
||||
// Small delay to allow server to bind and be ready
|
||||
sleep(Duration::from_millis(100)).await;
|
||||
|
||||
// Create MeshEngine and attach observability
|
||||
let mut mesh = MeshEngine::new(tmp.path())
|
||||
.with_observability(obs.clone());
|
||||
|
||||
// Perform a basic operation that emits a receipt
|
||||
mesh.node_join(
|
||||
"did:vm:node:test",
|
||||
"Test Node",
|
||||
NodeType::Infrastructure,
|
||||
HashMap::new(),
|
||||
"admin",
|
||||
)
|
||||
.expect("node_join");
|
||||
|
||||
// Wait a little to allow the receipt emission and metric recording
|
||||
sleep(Duration::from_millis(100)).await;
|
||||
|
||||
// Fetch metrics from observability server using dynamic address
|
||||
let metrics_url = format!("http://{}/metrics", addr);
|
||||
let resp = reqwest::get(&metrics_url)
|
||||
.await
|
||||
.expect("request failed");
|
||||
assert!(resp.status().is_success(), "metrics endpoint must return 200");
|
||||
|
||||
let body = resp.text().await.expect("read body");
|
||||
|
||||
// Basic asserts: receipts counter exists and mesh module is present
|
||||
assert!(
|
||||
body.contains("vaultmesh_receipts_total"),
|
||||
"metrics should expose receipts counter"
|
||||
);
|
||||
|
||||
// Assert mesh module appears in metrics
|
||||
assert!(
|
||||
body.contains("mesh"),
|
||||
"mesh module should appear in metrics"
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user