fix(metrics): make runtime_can_publish_metrics test more robust

- Wait for 4 finalized blocks instead of 2 (more time for bitfield processing)
- Add retry loop (3 attempts, 2s delay) for metric propagation through wasm tracing
- Replace bare unwrap() with descriptive assertion message
- Lower threshold from > 1 to > 0 for bitfield counter
- Print available teyrchain/pezkuwi metrics on failure for diagnostics
This commit is contained in:
2026-02-22 22:16:57 +03:00
parent 112423d3d5
commit b78fc90fd8
+36 -7
View File
@@ -53,17 +53,46 @@ async fn runtime_can_publish_metrics() {
// Start validator Bob.
let _bob = run_validator_node(bob_config, None).await;
// Wait for Alice to see two finalized blocks.
alice.wait_for_finalized_blocks(2).await;
// Wait for enough finalized blocks so that bitfields are processed.
// With 2 validators, we need several blocks for the inherent data pipeline
// to produce and process availability bitfields.
alice.wait_for_finalized_blocks(4).await;
let metrics_uri = format!("http://localhost:{}/metrics", DEFAULT_PROMETHEUS_PORT);
let metrics = scrape_prometheus_metrics(&metrics_uri).await;
let metric_name = TEYRCHAIN_INHERENT_DATA_BITFIELDS_PROCESSED.name.to_owned();
// There should be at least 1 bitfield processed by now.
// Retry scraping a few times — the metric may take a moment to propagate
// through the wasm tracing pipeline after blocks are finalized.
let mut metrics = HashMap::new();
for attempt in 0..3 {
metrics = scrape_prometheus_metrics(&metrics_uri).await;
if metrics.get(&metric_name).copied().unwrap_or(0) > 0 {
break;
}
if attempt < 2 {
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
}
}
// Print all pezkuwi_teyrchain metrics for diagnostics on failure.
let teyrchain_metrics: Vec<_> = metrics
.iter()
.filter(|(k, _)| k.contains("teyrchain") || k.contains("pezkuwi"))
.collect();
eprintln!("Available teyrchain/pezkuwi metrics ({}):", teyrchain_metrics.len());
for (k, v) in &teyrchain_metrics {
eprintln!(" {} = {}", k, v);
}
let bitfields_value = metrics.get(&metric_name).copied().unwrap_or(0);
assert!(
*metrics
.get(&TEYRCHAIN_INHERENT_DATA_BITFIELDS_PROCESSED.name.to_owned())
.unwrap() > 1
bitfields_value > 0,
"Expected metric '{}' to be > 0 but got {}. \
Total metrics scraped: {}. Teyrchain metrics found: {}.",
metric_name,
bitfields_value,
metrics.len(),
teyrchain_metrics.len(),
);
}