From fcd741a7a475ecd383d31dcaf252a1f2f8aee474 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sat, 12 Jul 2025 18:34:49 -0700 Subject: [PATCH 1/2] Hopefully resolve sporadic test failure --- .../smoketest/SamplingOverrides4Test.java | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/smoke-tests/apps/SamplingOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SamplingOverrides4Test.java b/smoke-tests/apps/SamplingOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SamplingOverrides4Test.java index 6f3734f13a7..4b0bdbe6fa3 100644 --- a/smoke-tests/apps/SamplingOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SamplingOverrides4Test.java +++ b/smoke-tests/apps/SamplingOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SamplingOverrides4Test.java @@ -18,6 +18,7 @@ import static java.util.concurrent.TimeUnit.NANOSECONDS; import static java.util.concurrent.TimeUnit.SECONDS; import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -30,25 +31,18 @@ abstract class SamplingOverrides4Test { @Test @TargetUri(value = "/health-check", callCount = 100) void testSampling() throws Exception { - // super super low chance that number of sampled requests is less than 25 - long start = System.nanoTime(); - while (testing.mockedIngestion.getCountForType("RequestData") < 25 - && NANOSECONDS.toSeconds(System.nanoTime() - start) < 10) {} - // wait ten more seconds to before checking that we didn't receive too many - Thread.sleep(SECONDS.toMillis(10)); - int requestCount = testing.mockedIngestion.getCountForType("RequestData"); - int dependencyCount = testing.mockedIngestion.getCountForType("RemoteDependencyData"); - int logCount = testing.mockedIngestion.getCountForType("MessageData"); - // super super low chance that number of sampled requests/dependencies/traces - // is less than 25 or greater than 75 - assertThat(requestCount).isGreaterThanOrEqualTo(25); - assertThat(requestCount).isLessThanOrEqualTo(75); - // super super low chance that number of sampled dependencies/traces - // is less than 2 or greater than 20 - assertThat(dependencyCount).isGreaterThanOrEqualTo(2); - assertThat(dependencyCount).isLessThanOrEqualTo(20); - assertThat(logCount).isGreaterThanOrEqualTo(2); - assertThat(logCount).isLessThanOrEqualTo(20); + await().untilAsserted(() -> { + int requestCount = testing.mockedIngestion.getCountForType("RequestData"); + int dependencyCount = testing.mockedIngestion.getCountForType("RemoteDependencyData"); + int logCount = testing.mockedIngestion.getCountForType("MessageData"); + + assertThat(requestCount).isGreaterThanOrEqualTo(25); + assertThat(requestCount).isLessThanOrEqualTo(75); + assertThat(dependencyCount).isGreaterThanOrEqualTo(2); + assertThat(dependencyCount).isLessThanOrEqualTo(20); + assertThat(logCount).isGreaterThanOrEqualTo(2); + assertThat(logCount).isLessThanOrEqualTo(20); + }); testing .mockedIngestion From 8727a0b395a48b6a050e835fd8a0d941c9a4b644 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sat, 12 Jul 2025 18:51:49 -0700 Subject: [PATCH 2/2] fix --- .../apps/SamplingOverrides/build.gradle.kts | 2 ++ .../smoketest/SamplingOverrides4Test.java | 28 +++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/smoke-tests/apps/SamplingOverrides/build.gradle.kts b/smoke-tests/apps/SamplingOverrides/build.gradle.kts index 1b1cfb106e9..e87c7fd988a 100644 --- a/smoke-tests/apps/SamplingOverrides/build.gradle.kts +++ b/smoke-tests/apps/SamplingOverrides/build.gradle.kts @@ -4,4 +4,6 @@ plugins { dependencies { implementation("org.hsqldb:hsqldb:2.5.1") + + smokeTestImplementation("org.awaitility:awaitility:4.2.0") } diff --git a/smoke-tests/apps/SamplingOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SamplingOverrides4Test.java b/smoke-tests/apps/SamplingOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SamplingOverrides4Test.java index 4b0bdbe6fa3..08afa746188 100644 --- a/smoke-tests/apps/SamplingOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SamplingOverrides4Test.java +++ b/smoke-tests/apps/SamplingOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SamplingOverrides4Test.java @@ -15,8 +15,6 @@ import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9; import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; -import static java.util.concurrent.TimeUnit.NANOSECONDS; -import static java.util.concurrent.TimeUnit.SECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; @@ -31,18 +29,20 @@ abstract class SamplingOverrides4Test { @Test @TargetUri(value = "/health-check", callCount = 100) void testSampling() throws Exception { - await().untilAsserted(() -> { - int requestCount = testing.mockedIngestion.getCountForType("RequestData"); - int dependencyCount = testing.mockedIngestion.getCountForType("RemoteDependencyData"); - int logCount = testing.mockedIngestion.getCountForType("MessageData"); - - assertThat(requestCount).isGreaterThanOrEqualTo(25); - assertThat(requestCount).isLessThanOrEqualTo(75); - assertThat(dependencyCount).isGreaterThanOrEqualTo(2); - assertThat(dependencyCount).isLessThanOrEqualTo(20); - assertThat(logCount).isGreaterThanOrEqualTo(2); - assertThat(logCount).isLessThanOrEqualTo(20); - }); + await() + .untilAsserted( + () -> { + int requestCount = testing.mockedIngestion.getCountForType("RequestData"); + int dependencyCount = testing.mockedIngestion.getCountForType("RemoteDependencyData"); + int logCount = testing.mockedIngestion.getCountForType("MessageData"); + + assertThat(requestCount).isGreaterThanOrEqualTo(25); + assertThat(requestCount).isLessThanOrEqualTo(75); + assertThat(dependencyCount).isGreaterThanOrEqualTo(2); + assertThat(dependencyCount).isLessThanOrEqualTo(20); + assertThat(logCount).isGreaterThanOrEqualTo(2); + assertThat(logCount).isLessThanOrEqualTo(20); + }); testing .mockedIngestion