From 4b71bcd8ff8b1a005b2f7e4599519ff23520510a Mon Sep 17 00:00:00 2001 From: damocles Date: Thu, 5 Nov 2026 00:53:43 +0100 Subject: [PATCH] metrics tests: compare labels sorted, the SDK keeps attributes in no fixed order --- swarm-claude-login/src/metrics.rs | 11 +++++++---- swarm-notify-router/src/metrics.rs | 7 +++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/swarm-claude-login/src/metrics.rs b/swarm-claude-login/src/metrics.rs index a47b8e40..024a4b4b 100644 --- a/swarm-claude-login/src/metrics.rs +++ b/swarm-claude-login/src/metrics.rs @@ -133,10 +133,13 @@ mod tests { for resource in exporter.get_finished_metrics().unwrap() { for scope in resource.scope_metrics() { for metric in scope.metrics().filter(|m| m.name() == name) { + // The SDK keeps attributes in no fixed order, so sort them. let labels = |attrs: &mut dyn Iterator| { - attrs + let mut all = attrs .map(|kv| (kv.key.to_string(), kv.value.to_string())) - .collect::>() + .collect::>(); + all.sort(); + all }; match metric.data() { AggregatedMetrics::U64(MetricData::Sum(sum)) => { @@ -180,8 +183,8 @@ mod tests { assert_eq!( got, vec![ - (vec![pair("step", "code"), pair("outcome", "failed")], 1), - (vec![pair("step", "code"), pair("outcome", "stored")], 2), + (vec![pair("outcome", "failed"), pair("step", "code")], 1), + (vec![pair("outcome", "stored"), pair("step", "code")], 2), ] ); } diff --git a/swarm-notify-router/src/metrics.rs b/swarm-notify-router/src/metrics.rs index d6c8f91b..36efdf08 100644 --- a/swarm-notify-router/src/metrics.rs +++ b/swarm-notify-router/src/metrics.rs @@ -190,10 +190,13 @@ mod tests { for resource in exporter.get_finished_metrics().unwrap() { for scope in resource.scope_metrics() { for metric in scope.metrics().filter(|m| m.name() == name) { + // The SDK keeps attributes in no fixed order, so sort them. let labels = |attrs: &mut dyn Iterator| { - attrs + let mut all = attrs .map(|kv| (kv.key.to_string(), kv.value.to_string())) - .collect::>() + .collect::>(); + all.sort(); + all }; match metric.data() { AggregatedMetrics::U64(MetricData::Sum(sum)) => {