Fix flaky test in testApproximateRangeWithSizeOverDefault by adjusting totalHits assertion logic #16433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses an issue in the
testApproximateRangeWithSizeOverDefault
method ofApproximatePointRangeQueryTests
, where the test would occasionally fail due to how Lucene handles total hits.By default,
search()
in Lucene'sIndexSearcher
provides an accurate count for up to 1000 hits.Beyond this threshold, Lucene may return a lower bound using GREATER_THAN_OR_EQUAL_TO for performance reasons (refer to the Lucene IndexSearcher documentation.)
In
testApproximateRangeWithSizeOverDefault
, the search range includes 12,001 documents, and the test would sometimes fail whenGREATER_THAN_OR_EQUAL_TO
occurred during the search.Changes:
EQUAL_TO
, the test checks for an exact count of 11000.GREATER_THAN_OR_EQUAL_TO
, the test ensures the hits are no less than 11000 and within the upper bound (maxHits).This issue is similar to OpenSearch PR #4270. I resolved it in a similar way. Special thanks to @dbwiddis for the valuable guidance.
Related Issues
Related #15807
Check List
API changes companion pull request created, if applicable.Public documentation issue/PR created, if applicable.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.