diff --git a/server/src/test/java/org/opensearch/index/IndexServiceTests.java b/server/src/test/java/org/opensearch/index/IndexServiceTests.java index db9f4bd305c79..14451ef21726e 100644 --- a/server/src/test/java/org/opensearch/index/IndexServiceTests.java +++ b/server/src/test/java/org/opensearch/index/IndexServiceTests.java @@ -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)); @@ -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