From a33258bac33fb7fe75dbac326581127310d8d143 Mon Sep 17 00:00:00 2001 From: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Date: Wed, 7 Oct 2026 06:39:22 -0400 Subject: [PATCH] test(relay): read the skip test's counters from one recorder snapshot DebuggingRecorder drains counters on each snapshot, so the publication counters read after the failure counter always saw zero. Read every counter from a single snapshot and also assert result="attempted" == 1, which proves the snapshot observed the pass. Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> --- .../buzz-relay/src/handlers/side_effects.rs | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/crates/buzz-relay/src/handlers/side_effects.rs b/crates/buzz-relay/src/handlers/side_effects.rs index 918a07d1f5..0ae324a98b 100644 --- a/crates/buzz-relay/src/handlers/side_effects.rs +++ b/crates/buzz-relay/src/handlers/side_effects.rs @@ -4273,30 +4273,41 @@ mod tests { }; assert_eq!((summary.repaired, summary.failed), (0, 0)); - assert_eq!(reconciliation_failures(&recorder), 0); assert_eq!(relay_signed_snapshots(&pool, id, &state).await, 1); - assert_eq!(publications(&recorder, "skipped"), 1); - assert_eq!(publications(&recorder, "succeeded"), 0); - } - - fn publications(recorder: &DebuggingRecorder, result: &str) -> u64 { - recorder + // One snapshot for every counter: taking a snapshot drains the + // recorder's counters, so a second read would see zero. + let counters: Vec<(String, Option, u64)> = recorder .snapshotter() .snapshot() .into_vec() .into_iter() - .filter(|(key, _, _, _)| { - key.key().name() == "buzz_nip43_membership_publications_total" - && key - .key() + .filter_map(|(key, _, _, value)| match value { + DebugValue::Counter(value) => Some(( + key.key().name().to_owned(), + key.key() .labels() - .any(|label| label.key() == "result" && label.value() == result) + .find(|label| label.key() == "result") + .map(|label| label.value().to_owned()), + value, + )), + _ => None, }) - .map(|(_, _, _, value)| match value { - DebugValue::Counter(value) => value, - other => panic!("publications_total must be a counter: {other:?}"), - }) - .sum() + .collect(); + let total = |name: &str, result: Option<&str>| -> u64 { + counters + .iter() + .filter(|(n, r, _)| n == name && r.as_deref() == result) + .map(|(_, _, value)| value) + .sum() + }; + let publications = "buzz_nip43_membership_publications_total"; + assert_eq!(total(publications, Some("attempted")), 1); + assert_eq!(total(publications, Some("skipped")), 1); + assert_eq!(total(publications, Some("succeeded")), 0); + assert_eq!( + total("buzz_nip43_membership_reconciliation_failures_total", None), + 0 + ); } } }