From 13a4006c472ed3033861e2bd5451a6cf5d726656 Mon Sep 17 00:00:00 2001 From: Albert Zaharovits Date: Thu, 26 Jun 2025 19:05:38 +0300 Subject: [PATCH] Fix ThreadPoolMergeSchedulerTests testSchedulerCloseWaitsForRunningMerge (#130078) This fixes a race condition in the test scenario, between the merge scheduler closing and the merge task being scheduled to run. The test scenario expects that the merge task runs when the scheduler is closed. If the merge scheduler is closed before the merge task is scheduled, the merge task will instead be scheduled as aborted. Fixes: https://github.com/elastic/elasticsearch/issues/125236 --- muted-tests.yml | 3 --- .../index/engine/ThreadPoolMergeSchedulerTests.java | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/muted-tests.yml b/muted-tests.yml index 54ae87714d58e..fcc3527e9c133 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -281,9 +281,6 @@ tests: - class: org.elasticsearch.search.basic.SearchWithRandomDisconnectsIT method: testSearchWithRandomDisconnects issue: https://github.com/elastic/elasticsearch/issues/122707 -- class: org.elasticsearch.index.engine.ThreadPoolMergeSchedulerTests - method: testSchedulerCloseWaitsForRunningMerge - issue: https://github.com/elastic/elasticsearch/issues/125236 - class: org.elasticsearch.packaging.test.DockerTests method: test020PluginsListWithNoPlugins issue: https://github.com/elastic/elasticsearch/issues/126232 diff --git a/server/src/test/java/org/elasticsearch/index/engine/ThreadPoolMergeSchedulerTests.java b/server/src/test/java/org/elasticsearch/index/engine/ThreadPoolMergeSchedulerTests.java index d88f7c67b0bbd..bea7697fd51c6 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/ThreadPoolMergeSchedulerTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/ThreadPoolMergeSchedulerTests.java @@ -612,11 +612,12 @@ public void testSchedulerCloseWaitsForRunningMerge() throws Exception { fail(e); } }); + // test expects that there definitely is a running merge before closing the merge scheduler + mergeRunningLatch.await(); + // closes the merge scheduler t.start(); try { assertTrue(t.isAlive()); - // wait for the merge to actually run - mergeRunningLatch.await(); // ensure the merge scheduler is effectively "closed" assertBusy(() -> { MergeSource mergeSource2 = mock(MergeSource.class);