36
36
/** This test is checking the object allocation path works with heap sampling. */
37
37
public class HeapMonitorStatObjectCorrectnessTest {
38
38
39
- // Do 200000 iterations and expect maxIteration / multiplier samples.
40
- private static final int maxIteration = 200000 ;
39
+ // Do 400000 iterations and expect maxIteration / multiplier samples.
40
+ private static final int maxIteration = 400_000 ;
41
41
private static BigObject obj ;
42
42
43
- private native static boolean statsHaveExpectedNumberSamples (int expected , int percentError );
43
+ // 15% error ensures a sanity test without becoming flaky.
44
+ // Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
45
+ // statistical geometric variable around the sampling interval. This means that the test could be
46
+ // unlucky and not achieve the mean average fast enough for the test case.
47
+ private static final int acceptedErrorPercentage = 15 ;
44
48
45
49
private static void allocate () {
46
50
emptyStorage ();
@@ -83,11 +87,7 @@ private static void testBigAllocationInterval() {
83
87
double expected = maxIteration ;
84
88
expected /= samplingMultiplier ;
85
89
86
- // 10% error ensures a sanity test without becoming flaky.
87
- // Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
88
- // statistical geometric variable around the sampling interval. This means that the test could be
89
- // unlucky and not achieve the mean average fast enough for the test case.
90
- if (!HeapMonitor .statsHaveExpectedNumberSamples ((int ) expected , 10 )) {
90
+ if (!HeapMonitor .statsHaveExpectedNumberSamples ((int ) expected , acceptedErrorPercentage )) {
91
91
throw new RuntimeException ("Statistics should show about " + expected + " samples." );
92
92
}
93
93
}
@@ -108,11 +108,7 @@ private static void testEveryAllocationSampled() {
108
108
109
109
double expected = maxIteration ;
110
110
111
- // 10% error ensures a sanity test without becoming flaky.
112
- // Flakiness is due to the fact that this test is dependent on the sampling interval, which is a
113
- // statistical geometric variable around the sampling interval. This means that the test could be
114
- // unlucky and not achieve the mean average fast enough for the test case.
115
- if (!HeapMonitor .statsHaveExpectedNumberSamples ((int ) expected , 10 )) {
111
+ if (!HeapMonitor .statsHaveExpectedNumberSamples ((int ) expected , acceptedErrorPercentage )) {
116
112
throw new RuntimeException ("Statistics should show about " + expected + " samples." );
117
113
}
118
114
}
0 commit comments