Skip to content

Commit

Permalink
Fix and unmute org.elasticsearch.script.StatsSummaryTests:testEqualsA…
Browse files Browse the repository at this point in the history
…ndHashCode (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.
  • Loading branch information
ChrisHegarty authored Oct 30, 2024
1 parent feea0a0 commit c6f7827
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ tests:
- class: org.elasticsearch.xpack.sql.qa.single_node.JdbcSqlSpecIT
method: test {case-functions.testUcaseInline3}
issue: https://github.com/elastic/elasticsearch/issues/112643
- class: org.elasticsearch.script.StatsSummaryTests
method: testEqualsAndHashCode
issue: https://github.com/elastic/elasticsearch/issues/112439
- class: org.elasticsearch.repositories.blobstore.testkit.analyze.HdfsRepositoryAnalysisRestIT
issue: https://github.com/elastic/elasticsearch/issues/112889
- class: org.elasticsearch.xpack.sql.qa.security.JdbcSqlSpecIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
}
Expand Down

0 comments on commit c6f7827

Please sign in to comment.