From cfc9d12acc3ffc6748108d3ce2749d4f5bf4ed41 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Tue, 17 Apr 2018 17:33:18 +0000 Subject: [PATCH] [TEST] test against scaled value instead of fixed epsilon in MovAvgIT When comparing doubles, fixed epsilons can fail because the absolute difference in values may be quite large, even though the relative difference is tiny (e.g. with two very large numbers). Instead, we can scale epsilon by the absolute value of the expected value. This means we are looking for a diff that is epsilon-percent away from the value, rather than just epsilon. This is basically checking the relative error using junit's assertEqual. Closes #29456, unmutes the test --- .../search/aggregations/pipeline/moving/avg/MovAvgIT.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgIT.java b/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgIT.java index 159b7e28b12..695a5777a53 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgIT.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgIT.java @@ -68,7 +68,6 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.core.IsNull.notNullValue; import static org.hamcrest.core.IsNull.nullValue; -@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/29456") @ESIntegTestCase.SuiteScopeTestCase public class MovAvgIT extends ESIntegTestCase { private static final String INTERVAL_FIELD = "l_value"; @@ -1296,7 +1295,7 @@ public class MovAvgIT extends ESIntegTestCase { } else { assertThat("[_count] movavg is null", countMovAvg, notNullValue()); assertEquals("[_count] movavg does not match expected [" + countMovAvg.value() + " vs " + expectedCount + "]", - countMovAvg.value(), expectedCount, 0.1); + countMovAvg.value(), expectedCount, 0.1 * Math.abs(countMovAvg.value())); } // This is a gap bucket @@ -1308,7 +1307,7 @@ public class MovAvgIT extends ESIntegTestCase { } else { assertThat("[value] movavg is null", valuesMovAvg, notNullValue()); assertEquals("[value] movavg does not match expected [" + valuesMovAvg.value() + " vs " + expectedValue + "]", - valuesMovAvg.value(), expectedValue, 0.1); + valuesMovAvg.value(), expectedValue, 0.1 * Math.abs(countMovAvg.value())); } }