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 (#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 committed Oct 30, 2024
1 parent 794e922 commit 8f460fb
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 @@ -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
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 8f460fb

Please sign in to comment.