Skip to content

Commit 4841617

Browse files
committed
Fixing flaky tests
Signed-off-by: Sriram Ganesh <[email protected]>
1 parent 728f806 commit 4841617

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

server/src/test/java/org/opensearch/index/engine/LeafSorterOptimizationTests.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929
import java.nio.file.Path;
3030
import java.util.Comparator;
3131

32+
import static org.hamcrest.Matchers.equalTo;
3233
import static org.hamcrest.Matchers.greaterThan;
3334
import static org.hamcrest.Matchers.notNullValue;
3435
import static org.junit.Assert.assertEquals;
3536
import static org.junit.Assert.assertThat;
3637

3738
public class LeafSorterOptimizationTests extends EngineTestCase {
3839

39-
public void testReadOnlyEngineUsesLeafSorter() throws IOException {
40+
public void testReadOnlyEngineConfiguresLeafSorter() throws IOException {
4041
Path translogPath = createTempDir();
4142
try (Store store = createStore()) {
4243
store.createEmpty(Version.CURRENT.luceneVersion);
@@ -145,27 +146,13 @@ public void testReadOnlyEngineUsesLeafSorter() throws IOException {
145146
// Always verify we have at least one leaf
146147
assertThat("Should have at least one leaf", reader.leaves().size(), greaterThan(0));
147148

148-
// Verify the leaf sorter is configured regardless of segment count
149+
// Test that ReadOnlyEngine can be created with a leaf sorter configured
150+
// and that it can acquire a searcher successfully
149151
assertThat("Leaf sorter should be configured", readOnlyEngine.config().getLeafSorter(), notNullValue());
150-
151-
// Test that the leaf sorter is configured and the engine has leaves
152-
// Note: The actual sorting behavior may vary depending on the engine implementation
153-
// and Lucene's internal segment management. The key test is that the leaf sorter
154-
// is properly configured and the engine can create a searcher with leaves.
152+
assertThat("Leaf sorter should match the configured one", readOnlyEngine.config().getLeafSorter(), equalTo(leafSorter));
153+
154+
// Verify basic functionality - we can read from the engine
155155
assertThat("Should have at least one leaf", reader.leaves().size(), greaterThan(0));
156-
157-
// Verify the leaf sorter is configured (this is the main test)
158-
assertThat("Leaf sorter should be configured", readOnlyEngine.config().getLeafSorter(), notNullValue());
159-
160-
// Log the leaf order for debugging (but don't fail the test)
161-
if (reader.leaves().size() > 1) {
162-
java.util.List<Integer> leafSizes = new java.util.ArrayList<>();
163-
for (org.apache.lucene.index.LeafReaderContext ctx : reader.leaves()) {
164-
leafSizes.add(ctx.reader().maxDoc());
165-
}
166-
// The test passes as long as the leaf sorter is configured
167-
// The actual sorting behavior is implementation-dependent
168-
}
169156
}
170157
}
171158
}

0 commit comments

Comments
 (0)