Skip to content
Snippets Groups Projects
Unverified Commit b4f5b64a authored by s0me0ne-unkn0wn's avatar s0me0ne-unkn0wn Committed by GitHub
Browse files

Generalize metric assertions (#189)

parent 1b124e59
Branches
No related merge requests found
Pipeline #455804 failed with stage
in 7 minutes and 50 seconds
......@@ -148,17 +148,27 @@ impl NetworkNode {
&self,
metric_name: impl Into<String>,
value: impl Into<f64>,
) -> Result<bool, anyhow::Error> {
let value: f64 = value.into();
self.assert_with(metric_name, |v| v == value).await
}
/// Assert on a metric value using a given predicate.
/// See [`assert`] description for details.
pub async fn assert_with(
&self,
metric_name: impl Into<String>,
predicate: impl Fn(f64) -> bool,
) -> Result<bool, anyhow::Error> {
let metric_name = metric_name.into();
let value = value.into();
let val = self.metric(&metric_name).await?;
if val == value {
if predicate(val) {
Ok(true)
} else {
// reload metrics
self.fetch_metrics().await?;
let val = self.metric(&metric_name).await?;
Ok(val == value)
Ok(predicate(val))
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment