From e098e837f713ce9ac83ed5c1b1319e1de2833462 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 12 Feb 2020 11:08:14 -0500 Subject: [PATCH] Fix testShouldPeriodicallyFlushAfterMerge (#52243) MockRandomMergePolicy randomly determines if a segment should use a compound format. This can cause a force merge performing two merges: (1) merging to a single segment, (2) rewriting the new segment using the compound format. If the second merge completes after we have flushed, then it can flip the flag shouldPeriodicallyFlushAfterBigMerge to true. Closes #52205 --- .../org/elasticsearch/index/engine/InternalEngineTests.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index a120a640feb..2fdd1f4c99d 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -5131,6 +5131,9 @@ public class InternalEngineTests extends EngineTestCase { } public void testShouldPeriodicallyFlushAfterMerge() throws Exception { + engine.close(); + // Do not use MockRandomMergePolicy as it can cause a force merge performing two merges. + engine = createEngine(copy(engine.config(), newMergePolicy(random(), false))); assertThat("Empty engine does not need flushing", engine.shouldPeriodicallyFlush(), equalTo(false)); ParsedDocument doc = testParsedDocument(Integer.toString(0), null, testDocumentWithTextField(), SOURCE, null);