Skip to content

Commit fcd741a

Browse files
committed
Hopefully resolve sporadic test failure
1 parent 7d4c26a commit fcd741a

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

smoke-tests/apps/SamplingOverrides/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SamplingOverrides4Test.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static java.util.concurrent.TimeUnit.NANOSECONDS;
1919
import static java.util.concurrent.TimeUnit.SECONDS;
2020
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.awaitility.Awaitility.await;
2122

2223
import org.junit.jupiter.api.Test;
2324
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -30,25 +31,18 @@ abstract class SamplingOverrides4Test {
3031
@Test
3132
@TargetUri(value = "/health-check", callCount = 100)
3233
void testSampling() throws Exception {
33-
// super super low chance that number of sampled requests is less than 25
34-
long start = System.nanoTime();
35-
while (testing.mockedIngestion.getCountForType("RequestData") < 25
36-
&& NANOSECONDS.toSeconds(System.nanoTime() - start) < 10) {}
37-
// wait ten more seconds to before checking that we didn't receive too many
38-
Thread.sleep(SECONDS.toMillis(10));
39-
int requestCount = testing.mockedIngestion.getCountForType("RequestData");
40-
int dependencyCount = testing.mockedIngestion.getCountForType("RemoteDependencyData");
41-
int logCount = testing.mockedIngestion.getCountForType("MessageData");
42-
// super super low chance that number of sampled requests/dependencies/traces
43-
// is less than 25 or greater than 75
44-
assertThat(requestCount).isGreaterThanOrEqualTo(25);
45-
assertThat(requestCount).isLessThanOrEqualTo(75);
46-
// super super low chance that number of sampled dependencies/traces
47-
// is less than 2 or greater than 20
48-
assertThat(dependencyCount).isGreaterThanOrEqualTo(2);
49-
assertThat(dependencyCount).isLessThanOrEqualTo(20);
50-
assertThat(logCount).isGreaterThanOrEqualTo(2);
51-
assertThat(logCount).isLessThanOrEqualTo(20);
34+
await().untilAsserted(() -> {
35+
int requestCount = testing.mockedIngestion.getCountForType("RequestData");
36+
int dependencyCount = testing.mockedIngestion.getCountForType("RemoteDependencyData");
37+
int logCount = testing.mockedIngestion.getCountForType("MessageData");
38+
39+
assertThat(requestCount).isGreaterThanOrEqualTo(25);
40+
assertThat(requestCount).isLessThanOrEqualTo(75);
41+
assertThat(dependencyCount).isGreaterThanOrEqualTo(2);
42+
assertThat(dependencyCount).isLessThanOrEqualTo(20);
43+
assertThat(logCount).isGreaterThanOrEqualTo(2);
44+
assertThat(logCount).isLessThanOrEqualTo(20);
45+
});
5246

5347
testing
5448
.mockedIngestion

0 commit comments

Comments
 (0)