From d46c206f29c760cbe911d1ee8b51ed501a84d14e Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Thu, 30 Sep 2021 12:44:29 -0400 Subject: [PATCH] [BUG] ConcurrentSnapshotsIT#testAssertMultipleSnapshotsAndPrimaryFailOver fails intermittently (#1311) Signed-off-by: Andriy Redko --- .../snapshots/ConcurrentSnapshotsIT.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/ConcurrentSnapshotsIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/ConcurrentSnapshotsIT.java index 02b37e28e93..a016704bc3a 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/ConcurrentSnapshotsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/ConcurrentSnapshotsIT.java @@ -530,7 +530,10 @@ public class ConcurrentSnapshotsIT extends AbstractSnapshotIntegTestCase { final String secondSnapshot = "snapshot-two"; final ActionFuture secondSnapshotResponse = startFullSnapshotFromMasterClient(repoName, secondSnapshot); - + + // make sure second snapshot is in progress before restarting data node + waitUntilInprogress(repoName, secondSnapshot, TimeValue.timeValueSeconds(5L)); + internalCluster().restartNode(dataNode, InternalTestCluster.EMPTY_CALLBACK); assertThat(firstSnapshotResponse.get().getSnapshotInfo().state(), is(SnapshotState.PARTIAL)); @@ -1382,4 +1385,17 @@ public class ConcurrentSnapshotsIT extends AbstractSnapshotIntegTestCase { waitForBlock(internalCluster().getMasterName(), blockedRepoName, TimeValue.timeValueSeconds(30L)); return fut; } + + private static void waitUntilInprogress(final String repoName, final String snapshotName, + TimeValue timeout) throws InterruptedException { + waitUntil(() -> + currentSnapshots(repoName) + .stream() + .filter(s -> s.snapshotId().getName().equals(snapshotName)) + .filter(s -> s.state() == SnapshotState.IN_PROGRESS) + .findAny() + .isPresent(), + timeout.millis(), + TimeUnit.MILLISECONDS); + } }