15
15
import static com .microsoft .applicationinsights .smoketest .EnvironmentValue .TOMCAT_8_JAVA_8_OPENJ9 ;
16
16
import static com .microsoft .applicationinsights .smoketest .EnvironmentValue .WILDFLY_13_JAVA_8 ;
17
17
import 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 ;
20
18
import static org .assertj .core .api .Assertions .assertThat ;
19
+ import static org .awaitility .Awaitility .await ;
21
20
22
21
import org .junit .jupiter .api .Test ;
23
22
import org .junit .jupiter .api .extension .RegisterExtension ;
@@ -30,25 +29,20 @@ abstract class SamplingOverrides4Test {
30
29
@ Test
31
30
@ TargetUri (value = "/health-check" , callCount = 100 )
32
31
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
+ });
52
46
53
47
testing
54
48
.mockedIngestion
0 commit comments