diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/AllocationIdIT.java b/server/src/test/java/org/elasticsearch/cluster/routing/AllocationIdIT.java index f9da7a1aa8e..c6d7f925a2c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/AllocationIdIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/AllocationIdIT.java @@ -224,15 +224,17 @@ public class AllocationIdIT extends ESIntegTestCase { } private void checkNoValidShardCopy(String indexName, ShardId shardId) throws Exception { - final ClusterAllocationExplanation explanation = - client().admin().cluster().prepareAllocationExplain() - .setIndex(indexName).setShard(shardId.id()).setPrimary(true) - .get().getExplanation(); + assertBusy(() -> { + final ClusterAllocationExplanation explanation = + client().admin().cluster().prepareAllocationExplain() + .setIndex(indexName).setShard(shardId.id()).setPrimary(true) + .get().getExplanation(); - final ShardAllocationDecision shardAllocationDecision = explanation.getShardAllocationDecision(); - assertThat(shardAllocationDecision.isDecisionTaken(), equalTo(true)); - assertThat(shardAllocationDecision.getAllocateDecision().getAllocationDecision(), - equalTo(AllocationDecision.NO_VALID_SHARD_COPY)); + final ShardAllocationDecision shardAllocationDecision = explanation.getShardAllocationDecision(); + assertThat(shardAllocationDecision.isDecisionTaken(), equalTo(true)); + assertThat(shardAllocationDecision.getAllocateDecision().getAllocationDecision(), + equalTo(AllocationDecision.NO_VALID_SHARD_COPY)); + }); } }