diff --git a/muted-tests.yml b/muted-tests.yml index cac83afc002f4..7a36148d2dcb7 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -151,9 +151,6 @@ tests: - class: org.elasticsearch.xpack.ml.integration.MlJobIT method: testGetJob_GivenNoSuchJob issue: https://github.com/elastic/elasticsearch/issues/112730 -- class: org.elasticsearch.script.StatsSummaryTests - method: testEqualsAndHashCode - issue: https://github.com/elastic/elasticsearch/issues/112439 - class: org.elasticsearch.xpack.ml.integration.MlJobIT method: testDeleteJobAfterMissingAliases issue: https://github.com/elastic/elasticsearch/issues/112823 diff --git a/server/src/test/java/org/elasticsearch/script/StatsSummaryTests.java b/server/src/test/java/org/elasticsearch/script/StatsSummaryTests.java index 9cfa586de11ab..1e3fdb4e6a9ff 100644 --- a/server/src/test/java/org/elasticsearch/script/StatsSummaryTests.java +++ b/server/src/test/java/org/elasticsearch/script/StatsSummaryTests.java @@ -75,9 +75,21 @@ public void testEqualsAndHashCode() { assertThat(stats1, equalTo(stats2)); assertThat(stats1.hashCode(), equalTo(stats2.hashCode())); + // Accumulators with same sum, but different counts are not equals + stats1.accept(1); + stats1.accept(1); + stats2.accept(2); + assertThat(stats1.getSum(), equalTo(stats2.getSum())); + assertThat(stats1.getCount(), not(equalTo(stats2.getCount()))); + assertThat(stats1, not(equalTo(stats2))); + assertThat(stats1.hashCode(), not(equalTo(stats2.hashCode()))); + // Accumulators with different values are not equals - randomDoubles(randomIntBetween(0, 20)).forEach(stats1); - randomDoubles(randomIntBetween(0, 20)).forEach(stats2); + stats1.reset(); + stats2.reset(); + randomDoubles(randomIntBetween(1, 20)).forEach(stats1.andThen(v -> stats2.accept(v + randomDoubleBetween(0.0, 1.0, false)))); + assertThat(stats1.getCount(), equalTo(stats2.getCount())); + assertThat(stats1.getSum(), not(equalTo(stats2.getSum()))); assertThat(stats1, not(equalTo(stats2))); assertThat(stats1.hashCode(), not(equalTo(stats2.hashCode()))); }