Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,19 @@ protected String forecast(String jobId, TimeValue duration, TimeValue expiresIn,

protected void waitForecastToFinish(String jobId, String forecastId) throws Exception {
// Forecasts can take an eternity to complete in the FIPS JVM
waitForecastStatus(inFipsJvm() ? 300 : 90, jobId, forecastId, ForecastRequestStats.ForecastRequestStatus.FINISHED);
int timeoutSeconds = inFipsJvm() ? 300 : 90;
// First wait for the forecast document to exist and be in a non-terminal state
// This handles the race condition where the document may be SCHEDULED or STARTED initially
waitForecastStatus(
timeoutSeconds,
jobId,
forecastId,
ForecastRequestStats.ForecastRequestStatus.SCHEDULED,
ForecastRequestStats.ForecastRequestStatus.STARTED,
ForecastRequestStats.ForecastRequestStatus.FINISHED
);
Comment on lines +249 to +259
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'flacky' to 'flaky' in the PR title.

Copilot uses AI. Check for mistakes.
// Then wait specifically for FINISHED status
waitForecastStatus(timeoutSeconds, jobId, forecastId, ForecastRequestStats.ForecastRequestStatus.FINISHED);
}

protected void waitForecastStatus(String jobId, String forecastId, ForecastRequestStats.ForecastRequestStatus... status)
Expand All @@ -261,6 +273,10 @@ protected void waitForecastStatus(
ForecastRequestStats.ForecastRequestStatus... status
) throws Exception {
assertBusy(() -> {
// Refresh the index to ensure recently indexed forecast stats documents are visible
indicesAdmin().prepareRefresh(AnomalyDetectorsIndex.jobResultsAliasedName(jobId))
.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_HIDDEN)
.get();
ForecastRequestStats forecastRequestStats = getForecastStats(jobId, forecastId);
assertThat(forecastRequestStats, is(notNullValue()));
assertThat(forecastRequestStats.getStatus(), in(status));
Expand Down