1515import static com .microsoft .applicationinsights .smoketest .EnvironmentValue .TOMCAT_8_JAVA_8_OPENJ9 ;
1616import static com .microsoft .applicationinsights .smoketest .EnvironmentValue .WILDFLY_13_JAVA_8 ;
1717import static com .microsoft .applicationinsights .smoketest .EnvironmentValue .WILDFLY_13_JAVA_8_OPENJ9 ;
18- import static java .util .concurrent .TimeUnit .NANOSECONDS ;
19- import static java .util .concurrent .TimeUnit .SECONDS ;
2018import static org .assertj .core .api .Assertions .assertThat ;
19+ import static org .awaitility .Awaitility .await ;
2120
2221import org .junit .jupiter .api .Test ;
2322import org .junit .jupiter .api .extension .RegisterExtension ;
@@ -30,25 +29,20 @@ abstract class SamplingOverrides4Test {
3029 @ Test
3130 @ TargetUri (value = "/health-check" , callCount = 100 )
3231 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 );
32+ await ()
33+ .untilAsserted (
34+ () -> {
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