Skip to content

Commit

Permalink
Fix for flaky test IndexServiceTests.testAsyncTranslogTrimTaskOnClose…
Browse files Browse the repository at this point in the history
…dIndex (opensearch-project#11337)

Signed-off-by: Ankit Kala <ankikala@amazon.com>
  • Loading branch information
ankitkala authored Dec 1, 2023
1 parent 77a4daf commit 69cc2a1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions server/src/test/java/org/opensearch/index/IndexServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,7 @@ public void testAsyncTranslogTrimTaskOnClosedIndex() throws Exception {
assertTrue(indexService.getTrimTranslogTask().mustReschedule());

final Engine readOnlyEngine = getEngine(indexService.getShard(0));
assertBusy(
() -> assertThat(
readOnlyEngine.translogManager().getTranslogStats().getTranslogSizeInBytes(),
equalTo((long) Translog.DEFAULT_HEADER_SIZE_IN_BYTES)
)
);
assertBusy(() -> assertTrue(isTranslogEmpty(readOnlyEngine)));

assertAcked(client().admin().indices().prepareOpen("test").setWaitForActiveShards(ActiveShardCount.DEFAULT));

Expand All @@ -467,6 +462,12 @@ public void testAsyncTranslogTrimTaskOnClosedIndex() throws Exception {
assertThat(translog.stats().estimatedNumberOfOperations(), equalTo(0));
}

boolean isTranslogEmpty(Engine engine) {
long tlogSize = engine.translogManager().getTranslogStats().getTranslogSizeInBytes();
// translog contains 1(or 2 in some corner cases) empty readers.
return tlogSize == Translog.DEFAULT_HEADER_SIZE_IN_BYTES || tlogSize == 2 * Translog.DEFAULT_HEADER_SIZE_IN_BYTES;
}

public void testIllegalFsyncInterval() {
Settings settings = Settings.builder()
.put(IndexSettings.INDEX_TRANSLOG_SYNC_INTERVAL_SETTING.getKey(), "0ms") // disable
Expand Down

0 comments on commit 69cc2a1

Please sign in to comment.