Skip to content

Commit d321d73

Browse files
ChrisHegartyjfreden
authored andcommitted
Fix and unmute org.elasticsearch.script.StatsSummaryTests:testEqualsAndHashCode (elastic#115922)
This commit fixes and unmutes org.elasticsearch.script.StatsSummaryTests:testEqualsAndHashCode. Previously, there was no guarantee that the doubles added to stats1 and stats2 will be different. In fact, the count may even be zero - which we seen in one particular failure. The simplest thing here, to avoid this potential situation, is to ensure that there is at least one value, and that the values added to each stats instance are different.
1 parent bca1743 commit d321d73

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ tests:
103103
- class: org.elasticsearch.xpack.sql.qa.single_node.JdbcSqlSpecIT
104104
method: test {case-functions.testUcaseInline3}
105105
issue: https://github.com/elastic/elasticsearch/issues/112643
106-
- class: org.elasticsearch.script.StatsSummaryTests
107-
method: testEqualsAndHashCode
108-
issue: https://github.com/elastic/elasticsearch/issues/112439
109106
- class: org.elasticsearch.repositories.blobstore.testkit.analyze.HdfsRepositoryAnalysisRestIT
110107
issue: https://github.com/elastic/elasticsearch/issues/112889
111108
- class: org.elasticsearch.xpack.sql.qa.security.JdbcSqlSpecIT

server/src/test/java/org/elasticsearch/script/StatsSummaryTests.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,21 @@ public void testEqualsAndHashCode() {
7575
assertThat(stats1, equalTo(stats2));
7676
assertThat(stats1.hashCode(), equalTo(stats2.hashCode()));
7777

78+
// Accumulators with same sum, but different counts are not equals
79+
stats1.accept(1);
80+
stats1.accept(1);
81+
stats2.accept(2);
82+
assertThat(stats1.getSum(), equalTo(stats2.getSum()));
83+
assertThat(stats1.getCount(), not(equalTo(stats2.getCount())));
84+
assertThat(stats1, not(equalTo(stats2)));
85+
assertThat(stats1.hashCode(), not(equalTo(stats2.hashCode())));
86+
7887
// Accumulators with different values are not equals
79-
randomDoubles(randomIntBetween(0, 20)).forEach(stats1);
80-
randomDoubles(randomIntBetween(0, 20)).forEach(stats2);
88+
stats1.reset();
89+
stats2.reset();
90+
randomDoubles(randomIntBetween(1, 20)).forEach(stats1.andThen(v -> stats2.accept(v + randomDoubleBetween(0.0, 1.0, false))));
91+
assertThat(stats1.getCount(), equalTo(stats2.getCount()));
92+
assertThat(stats1.getSum(), not(equalTo(stats2.getSum())));
8193
assertThat(stats1, not(equalTo(stats2)));
8294
assertThat(stats1.hashCode(), not(equalTo(stats2.hashCode())));
8395
}

0 commit comments

Comments
 (0)