From 2383acaa89f82a5a0a7272d7f0e48f6721f75e9a Mon Sep 17 00:00:00 2001 From: Henning Andersen <33268011+henningandersen@users.noreply.github.com> Date: Tue, 3 Sep 2019 17:29:28 +0200 Subject: [PATCH] Fix testSyncFailsIfOperationIsInFlight (#46269) testSyncFailsIfOperationIsInFlight could fail due to the index request spawing a GCP sync (new since 7.4). Test now waits for it to finish before testing that flushed sync fails. --- .../indices/flush/SyncedFlushSingleNodeTests.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java b/server/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java index 9d7f3d5e253..0a97b4978f3 100644 --- a/server/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java +++ b/server/src/test/java/org/elasticsearch/indices/flush/SyncedFlushSingleNodeTests.java @@ -38,7 +38,6 @@ import org.elasticsearch.threadpool.ThreadPool; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutionException; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -110,12 +109,18 @@ public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase { assertTrue(response.success()); } - public void testSyncFailsIfOperationIsInFlight() throws InterruptedException, ExecutionException { + public void testSyncFailsIfOperationIsInFlight() throws Exception { createIndex("test"); client().prepareIndex("test", "test", "1").setSource("{}", XContentType.JSON).get(); IndexService test = getInstanceFromNode(IndicesService.class).indexService(resolveIndex("test")); IndexShard shard = test.getShardOrNull(0); + // wait for the GCP sync spawned from the index request above to complete to avoid that request disturbing the check below + assertBusy(() -> { + assertEquals(0, shard.getLastSyncedGlobalCheckpoint()); + assertEquals(0, shard.getActiveOperationsCount()); + }); + SyncedFlushService flushService = getInstanceFromNode(SyncedFlushService.class); final ShardId shardId = shard.shardId(); PlainActionFuture fut = new PlainActionFuture<>();