diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADBatchAnomalyResultTransportActionTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADBatchAnomalyResultTransportActionTests.java index 0380c0d9..585df8b9 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADBatchAnomalyResultTransportActionTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/transport/ADBatchAnomalyResultTransportActionTests.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.time.Instant; import java.time.temporal.ChronoUnit; +import java.util.concurrent.TimeUnit; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.get.GetResponse; @@ -142,12 +143,13 @@ public void testHistoricalDetectorExceedsMaxRunningTaskLimit() throws IOExceptio updateTransientSettings(ImmutableMap.of(MAX_BATCH_TASK_PER_NODE.getKey(), 1)); updateTransientSettings(ImmutableMap.of(BATCH_TASK_PIECE_INTERVAL_SECONDS.getKey(), 5)); DetectionDateRange dateRange = new DetectionDateRange(startTime, endTime); - for (int i = 0; i < getDataNodes().size(); i++) { - client().execute(ADBatchAnomalyResultAction.INSTANCE, adBatchAnomalyResultRequest(dateRange)); + int totalDataNodes = getDataNodes().size(); + for (int i = 0; i < totalDataNodes; i++) { + client().execute(ADBatchAnomalyResultAction.INSTANCE, adBatchAnomalyResultRequest(dateRange)).actionGet(5000); } + waitUntil(() -> countDocs(CommonName.DETECTION_STATE_INDEX) >= totalDataNodes, 10, TimeUnit.SECONDS); ADBatchAnomalyResultRequest request = adBatchAnomalyResultRequest(dateRange); - RuntimeException exception = expectThrowsAnyOf( ImmutableList.of(LimitExceededException.class, NotSerializableExceptionWrapper.class), () -> client().execute(ADBatchAnomalyResultAction.INSTANCE, request).actionGet(5000)