From 75661286020288b84c4cb138b21b1ff132c53590 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Tue, 14 May 2024 18:05:19 -0700 Subject: [PATCH] [nexus] deflake `test_instance_watcher_metrics` (#5768) Presently, `test_instance_watcher_metrics` will wait for the `instance_watcher` background task to have run before making assertions about metrics, but it does *not* ensure that oximeter has actually collected those metrics. This can result in flaky failures --- see #5752. This commit adds explicit calls to `oximeter.force_collect()` prior to making assertions, to ensure that the latest metrics have been collected. Fixes #5752 --- nexus/tests/integration_tests/metrics.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nexus/tests/integration_tests/metrics.rs b/nexus/tests/integration_tests/metrics.rs index 71d18f95ee..abcc7f1c75 100644 --- a/nexus/tests/integration_tests/metrics.rs +++ b/nexus/tests/integration_tests/metrics.rs @@ -329,6 +329,7 @@ async fn test_instance_watcher_metrics( let client = &cptestctx.external_client; let internal_client = &cptestctx.internal_client; let nexus = &cptestctx.server.server_context().nexus; + let oximeter = &cptestctx.oximeter; // TODO(eliza): consider factoring this out to a generic // `activate_background_task` function in `nexus-test-utils` eventually? @@ -399,6 +400,8 @@ async fn test_instance_watcher_metrics( ) .await .unwrap(); + // Make sure that the latest metrics have been collected. + oximeter.force_collect().await; }; #[track_caller] @@ -443,11 +446,8 @@ async fn test_instance_watcher_metrics( let project = create_project_and_pool(&client).await; let project_name = project.identity.name.as_str(); // Wait until Nexus registers as a producer with Oximeter. - wait_for_producer( - &cptestctx.oximeter, - cptestctx.server.server_context().nexus.id(), - ) - .await; + wait_for_producer(&oximeter, cptestctx.server.server_context().nexus.id()) + .await; eprintln!("--- creating instance 1 ---"); let instance1 = create_instance(&client, project_name, "i-1").await;