Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions smoke-tests/apps/SamplingOverrides/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ plugins {

dependencies {
implementation("org.hsqldb:hsqldb:2.5.1")

smokeTestImplementation("org.awaitility:awaitility:4.2.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
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;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -30,25 +29,20 @@ 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
Expand Down