diff --git a/muted-tests.yml b/muted-tests.yml index e06f4c661ca1a..d3510c7467925 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -538,15 +538,6 @@ tests: - class: org.elasticsearch.xpack.esql.qa.multi_node.EsqlSpecIT method: test {knn-function.KnnSearchWithKOption SYNC} issue: https://github.com/elastic/elasticsearch/issues/129512 -- class: org.elasticsearch.xpack.logsdb.qa.StandardVersusStandardReindexedIntoLogsDbChallengeRestIT - method: testMatchAllQuery - issue: https://github.com/elastic/elasticsearch/issues/129527 -- class: org.elasticsearch.xpack.logsdb.qa.BulkChallengeRestIT - method: testMatchAllQuery - issue: https://github.com/elastic/elasticsearch/issues/129528 -- class: org.elasticsearch.xpack.logsdb.qa.StoredSourceLogsDbVersusReindexedLogsDbChallengeRestIT - method: testMatchAllQuery - issue: https://github.com/elastic/elasticsearch/issues/129529 - class: org.elasticsearch.index.engine.ThreadPoolMergeExecutorServiceTests method: testIORateIsAdjustedForAllRunningMergeTasks issue: https://github.com/elastic/elasticsearch/issues/129531 diff --git a/test/framework/src/main/java/org/elasticsearch/datageneration/matchers/source/DynamicFieldMatcher.java b/test/framework/src/main/java/org/elasticsearch/datageneration/matchers/source/DynamicFieldMatcher.java index 1da503a9b792f..ef3764bc01fcd 100644 --- a/test/framework/src/main/java/org/elasticsearch/datageneration/matchers/source/DynamicFieldMatcher.java +++ b/test/framework/src/main/java/org/elasticsearch/datageneration/matchers/source/DynamicFieldMatcher.java @@ -17,14 +17,14 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; +import java.util.function.Supplier; import static org.elasticsearch.datageneration.matchers.Messages.formatErrorMessage; import static org.elasticsearch.datageneration.matchers.Messages.prettyPrintCollections; class DynamicFieldMatcher { + private static final double FLOAT_ERROR_MARGIN = 1e-8; private final XContentBuilder actualMappings; private final Settings.Builder actualSettings; private final XContentBuilder expectedMappings; @@ -62,31 +62,46 @@ public MatchResult match(List actual, List expected) { var normalizedActual = normalizeDoubles(actual); var normalizedExpected = normalizeDoubles(expected); + Supplier noMatchSupplier = () -> MatchResult.noMatch( + formatErrorMessage( + actualMappings, + actualSettings, + expectedMappings, + expectedSettings, + "Values of dynamically mapped field containing double values don't match after normalization, normalized " + + prettyPrintCollections(normalizedActual, normalizedExpected) + ) + ); - return normalizedActual.equals(normalizedExpected) - ? MatchResult.match() - : MatchResult.noMatch( - formatErrorMessage( - actualMappings, - actualSettings, - expectedMappings, - expectedSettings, - "Values of dynamically mapped field containing double values don't match after normalization, normalized " - + prettyPrintCollections(normalizedActual, normalizedExpected) - ) - ); + if (normalizedActual.size() != normalizedExpected.size()) { + return noMatchSupplier.get(); + } + + for (int i = 0; i < normalizedActual.size(); i++) { + if (floatEquals(normalizedActual.get(i), normalizedExpected.get(i)) == false) { + return noMatchSupplier.get(); + } + } + + return MatchResult.match(); } return matchWithGenericMatcher(actual, expected); } - private static Set normalizeDoubles(List values) { + private static List normalizeDoubles(List values) { if (values == null) { - return Set.of(); + return List.of(); } Function toFloat = (o) -> o instanceof Number n ? n.floatValue() : Float.parseFloat((String) o); - return values.stream().filter(Objects::nonNull).map(toFloat).collect(Collectors.toSet()); + + // We skip nulls because they trip the pretty print collections. + return values.stream().filter(Objects::nonNull).map(toFloat).toList(); + } + + private static boolean floatEquals(Float actual, Float expected) { + return Math.abs(actual - expected) < FLOAT_ERROR_MARGIN; } private MatchResult matchWithGenericMatcher(List actualValues, List expectedValues) {