From 1d7207e254447d4d1d1ecae4ca3e0c936e6399a7 Mon Sep 17 00:00:00 2001 From: INDRAJIT BANERJEE Date: Wed, 9 Aug 2023 17:24:22 +0530 Subject: [PATCH] Fixing SnapshotResiliencyTests.testTransportGetSnapshotsAction (#9189) * Fixing flaky test testTransportGetSnapshotsAction Signed-off-by: INDRAJIT BANERJEE Signed-off-by: Indrajit Banerjee Signed-off-by: Kaushal Kumar --- CHANGELOG.md | 2 +- .../snapshots/SnapshotResiliencyTests.java | 52 +++++++++---------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5ab51e9b162e..dcaee5b3fc57b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -129,4 +129,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Security [Unreleased 3.0]: https://github.com/opensearch-project/OpenSearch/compare/2.x...HEAD -[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.10...2.x \ No newline at end of file +[Unreleased 2.x]: https://github.com/opensearch-project/OpenSearch/compare/2.10...2.x diff --git a/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java b/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java index c04e2821d7931..ce918ba40d8be 100644 --- a/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java +++ b/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java @@ -798,43 +798,41 @@ public void testTransportGetSnapshotsAction() { setupTestCluster(randomFrom(1, 3, 5), randomIntBetween(2, 10)); String repoName = "repo"; - final String[] snapshotsList = { "snapshot-1", "snapshot-2" }; - final String[] indexList = { "index-1", "index-2" }; + final String[] snapshotsList = { "snapshot-1" }; + final String index = "index-1"; final int shards = randomIntBetween(1, 10); TestClusterNodes.TestClusterNode clusterManagerNode = testClusterNodes.currentClusterManager( testClusterNodes.nodes.values().iterator().next().clusterService.state() ); - for (int i = 0; i < snapshotsList.length; i++) { - final StepListener createSnapshotResponseStepListener = new StepListener<>(); - final String snapshot = snapshotsList[i]; - final String index = indexList[i]; - continueOrDie( - createRepoAndIndex(repoName, index, shards), - createSnapshotResponse -> client().admin() - .cluster() - .prepareCreateSnapshot(repoName, snapshot) - .setWaitForCompletion(true) - .execute(createSnapshotResponseStepListener) - ); - } - deterministicTaskQueue.runAllRunnableTasks(); + final StepListener createSnapshotResponseStepListener = new StepListener<>(); + final String snapshot = snapshotsList[0]; + continueOrDie( + createRepoAndIndex(repoName, index, shards), + createSnapshotResponse -> client().admin() + .cluster() + .prepareCreateSnapshot(repoName, snapshot) + .setWaitForCompletion(true) + .execute(createSnapshotResponseStepListener) + ); + + continueOrDie(createSnapshotResponseStepListener, createSnapshotResponse -> { - TransportAction getSnapshotsAction = clusterManagerNode.actions.get(GetSnapshotsAction.INSTANCE); - TransportGetSnapshotsAction transportGetSnapshotsAction = (TransportGetSnapshotsAction) getSnapshotsAction; - GetSnapshotsRequest repoSnapshotRequest = new GetSnapshotsRequest().repository(repoName).snapshots(snapshotsList); + TransportAction getSnapshotsAction = clusterManagerNode.actions.get(GetSnapshotsAction.INSTANCE); + TransportGetSnapshotsAction transportGetSnapshotsAction = (TransportGetSnapshotsAction) getSnapshotsAction; + GetSnapshotsRequest repoSnapshotRequest = new GetSnapshotsRequest().repository(repoName).snapshots(snapshotsList); - transportGetSnapshotsAction.execute(null, repoSnapshotRequest, ActionListener.wrap(repoSnapshotResponse -> { - assertNotNull("Snapshot list should not be null", repoSnapshotResponse.getSnapshots()); - assertThat(repoSnapshotResponse.getSnapshots(), hasSize(2)); - List snapshotInfos = repoSnapshotResponse.getSnapshots(); - for (SnapshotInfo snapshotInfo : snapshotInfos) { + transportGetSnapshotsAction.execute(null, repoSnapshotRequest, ActionListener.wrap(repoSnapshotResponse -> { + assertNotNull("Snapshot list should not be null", repoSnapshotResponse.getSnapshots()); + assertThat(repoSnapshotResponse.getSnapshots(), hasSize(1)); + List snapshotInfos = repoSnapshotResponse.getSnapshots(); + SnapshotInfo snapshotInfo = snapshotInfos.get(0); assertEquals(SnapshotState.SUCCESS, snapshotInfo.state()); assertEquals(0, snapshotInfo.failedShards()); - assertTrue(Arrays.stream(snapshotsList).anyMatch(snapshotInfo.snapshotId().getName()::equals)); - } - }, exception -> { throw new AssertionError(exception); })); + assertEquals(snapshotInfo.snapshotId().getName(), snapshotsList[0]); + }, exception -> { throw new AssertionError(exception); })); + }); } public void testTransportGetCurrentSnapshotsAction() {