From 9aa6841a4f083f3d43a8b9cf327573b7a29a4110 Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Sat, 2 Dec 2023 22:24:52 +0000 Subject: [PATCH] Add an uptime test --- linkerd/metrics/src/uptime.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/linkerd/metrics/src/uptime.rs b/linkerd/metrics/src/uptime.rs index 93e65468d5..3aa442d432 100644 --- a/linkerd/metrics/src/uptime.rs +++ b/linkerd/metrics/src/uptime.rs @@ -30,3 +30,23 @@ impl prom::core::Collector for Uptime { self.metric.collect() } } + +#[cfg(test)] +mod tests { + use super::*; + use prom::core::Collector; + use tokio::time; + + #[tokio::test(flavor = "current_thread", start_paused = true)] + async fn test_uptime() { + let uptime = Uptime::default(); + + time::sleep(time::Duration::from_secs(10)).await; + + assert_eq!( + uptime.collect()[0].get_metric()[0].get_gauge().get_value(), + 10.0, + "Uptime should increase over time" + ); + } +}