Skip to content

Commit f9d96c4

Browse files
committed
[TESTS] Improve BenchmarkIntegrationTest's check that percentiles are increasing.
Percentiles are supposed to be monotonically increasing but floating-point rounding issues can come into play and make the test fail if checks are too strict.
1 parent eec6f1b commit f9d96c4

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/test/java/org/elasticsearch/action/bench/BenchmarkIntegrationTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import org.junit.Before;
3131
import org.junit.Test;
3232

33-
import java.math.BigDecimal;
34-
import java.math.RoundingMode;
3533
import java.util.HashMap;
3634
import java.util.Map;
3735
import java.util.concurrent.TimeUnit;
@@ -232,17 +230,14 @@ private void validateCompetitionResult(CompetitionResult result, BenchmarkSettin
232230

233231
private void validatePercentiles(Map<Double, Double> percentiles) {
234232
int i = 0;
235-
Double last = null;
233+
double last = Double.NEGATIVE_INFINITY;
236234
for (Map.Entry<Double, Double> entry : percentiles.entrySet()) {
237235
assertThat(entry.getKey(), equalTo(BenchmarkSettings.DEFAULT_PERCENTILES[i++]));
238-
if (last != null) {
239-
assertThat(entry.getValue(), greaterThanOrEqualTo(last));
240-
}
241236
// This is a hedge against rounding errors. Sometimes two adjacent percentile values will
242237
// be nearly equivalent except for some insignificant decimal places. In such cases we
243238
// want the two values to compare as equal.
244-
final BigDecimal bd = new BigDecimal(entry.getValue()).setScale(2, RoundingMode.HALF_DOWN);
245-
last = bd.doubleValue();
239+
assertThat(entry.getValue(), greaterThanOrEqualTo(last - 1e-6));
240+
last = entry.getValue();
246241
}
247242
}
248243

0 commit comments

Comments
 (0)