Skip to content

Commit 802f2e6

Browse files
SwethaGupthaSwetha Guptha
and
Swetha Guptha
authored
Fix flaky test RecoveryFromGatewayIT.testMultipleReplicaShardAssignmentWithDelayedAllocationAndDifferentNodeStartTimeInBatchMode (opensearch-project#14424)
Signed-off-by: Swetha Guptha <gupthasg@amazon.com> Co-authored-by: Swetha Guptha <gupthasg@amazon.com>
1 parent 120678d commit 802f2e6

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

‎server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java

+19-25
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import org.apache.lucene.index.CorruptIndexException;
3636
import org.opensearch.Version;
37-
import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse;
3837
import org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction;
3938
import org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest;
4039
import org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction;
@@ -101,6 +100,8 @@
101100
import java.util.Map;
102101
import java.util.Set;
103102
import java.util.concurrent.ExecutionException;
103+
import java.util.concurrent.TimeUnit;
104+
import java.util.function.BooleanSupplier;
104105
import java.util.stream.Collectors;
105106
import java.util.stream.IntStream;
106107

@@ -883,17 +884,20 @@ public void testMultipleReplicaShardAssignmentWithDelayedAllocationAndDifferentN
883884
assertEquals(YELLOW, health.getStatus());
884885
assertEquals(2, health.getUnassignedShards());
885886
// shard should be unassigned because of Allocation_Delayed
886-
ClusterAllocationExplainResponse allocationExplainResponse = client().admin()
887-
.cluster()
888-
.prepareAllocationExplain()
889-
.setIndex("test")
890-
.setShard(0)
891-
.setPrimary(false)
892-
.get();
893-
assertEquals(
894-
AllocationDecision.ALLOCATION_DELAYED,
895-
allocationExplainResponse.getExplanation().getShardAllocationDecision().getAllocateDecision().getAllocationDecision()
887+
BooleanSupplier delayedShardAllocationStatusVerificationSupplier = () -> AllocationDecision.ALLOCATION_DELAYED.equals(
888+
client().admin()
889+
.cluster()
890+
.prepareAllocationExplain()
891+
.setIndex("test")
892+
.setShard(0)
893+
.setPrimary(false)
894+
.get()
895+
.getExplanation()
896+
.getShardAllocationDecision()
897+
.getAllocateDecision()
898+
.getAllocationDecision()
896899
);
900+
waitUntil(delayedShardAllocationStatusVerificationSupplier, 2, TimeUnit.MINUTES);
897901

898902
logger.info("--> restarting the node 1");
899903
internalCluster().startDataOnlyNode(
@@ -903,26 +907,16 @@ public void testMultipleReplicaShardAssignmentWithDelayedAllocationAndDifferentN
903907
assertTrue(clusterRerouteResponse.isAcknowledged());
904908
ensureStableCluster(6);
905909
waitUntil(
906-
() -> client().admin().cluster().health(Requests.clusterHealthRequest().timeout("5m")).actionGet().getInitializingShards() == 0
910+
() -> client().admin().cluster().health(Requests.clusterHealthRequest().timeout("5m")).actionGet().getActiveShards() == 3,
911+
2,
912+
TimeUnit.MINUTES
907913
);
908-
909914
health = client().admin().cluster().health(Requests.clusterHealthRequest().timeout("5m")).actionGet();
910915
assertFalse(health.isTimedOut());
911916
assertEquals(YELLOW, health.getStatus());
912917
assertEquals(1, health.getUnassignedShards());
913918
assertEquals(1, health.getDelayedUnassignedShards());
914-
allocationExplainResponse = client().admin()
915-
.cluster()
916-
.prepareAllocationExplain()
917-
.setIndex("test")
918-
.setShard(0)
919-
.setPrimary(false)
920-
.get();
921-
assertEquals(
922-
AllocationDecision.ALLOCATION_DELAYED,
923-
allocationExplainResponse.getExplanation().getShardAllocationDecision().getAllocateDecision().getAllocationDecision()
924-
);
925-
919+
waitUntil(delayedShardAllocationStatusVerificationSupplier, 2, TimeUnit.MINUTES);
926920
logger.info("--> restarting the node 0");
927921
internalCluster().startDataOnlyNode(
928922
Settings.builder().put("node.name", nodesWithReplicaShards.get(1)).put(replicaNode1DataPathSettings).build()

0 commit comments

Comments
 (0)