[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.
This commit is contained in:
parent
78e39882ee
commit
caacce9429
|
@ -30,8 +30,6 @@ import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -232,17 +230,14 @@ public class BenchmarkIntegrationTest extends ElasticsearchIntegrationTest {
|
||||||
|
|
||||||
private void validatePercentiles(Map<Double, Double> percentiles) {
|
private void validatePercentiles(Map<Double, Double> percentiles) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Double last = null;
|
double last = Double.NEGATIVE_INFINITY;
|
||||||
for (Map.Entry<Double, Double> entry : percentiles.entrySet()) {
|
for (Map.Entry<Double, Double> entry : percentiles.entrySet()) {
|
||||||
assertThat(entry.getKey(), equalTo(BenchmarkSettings.DEFAULT_PERCENTILES[i++]));
|
assertThat(entry.getKey(), equalTo(BenchmarkSettings.DEFAULT_PERCENTILES[i++]));
|
||||||
if (last != null) {
|
|
||||||
assertThat(entry.getValue(), greaterThanOrEqualTo(last));
|
|
||||||
}
|
|
||||||
// This is a hedge against rounding errors. Sometimes two adjacent percentile values will
|
// This is a hedge against rounding errors. Sometimes two adjacent percentile values will
|
||||||
// be nearly equivalent except for some insignificant decimal places. In such cases we
|
// be nearly equivalent except for some insignificant decimal places. In such cases we
|
||||||
// want the two values to compare as equal.
|
// want the two values to compare as equal.
|
||||||
final BigDecimal bd = new BigDecimal(entry.getValue()).setScale(2, RoundingMode.HALF_DOWN);
|
assertThat(entry.getValue(), greaterThanOrEqualTo(last - 1e-6));
|
||||||
last = bd.doubleValue();
|
last = entry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue