Skip to content

Commit

Permalink
[ML] Functional tests - stabilize module tests (#102708) (#102744)
Browse files Browse the repository at this point in the history
This PR stabilizes the `setupModule` API tests by increasing the timeout for the jobs to finish.

Co-authored-by: Robert Oskamp <robert.oskamp@elastic.co>
  • Loading branch information
kibanamachine and pheyos committed Jun 21, 2021
1 parent 4f99200 commit b702a61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions x-pack/test/api_integration/apis/ml/modules/setup_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1146,8 +1146,8 @@ export default ({ getService }: FtrProviderContext) => {
if (testData.requestBody.startDatafeed === true) {
await ml.api.waitForADJobRecordCountToBePositive(job.jobId);
}
await ml.api.waitForJobState(job.jobId, job.jobState);
await ml.api.waitForDatafeedState(datafeedId, job.datafeedState);
await ml.api.waitForDatafeedState(datafeedId, job.datafeedState, 4 * 60 * 1000);
await ml.api.waitForJobState(job.jobId, job.jobState, 4 * 60 * 1000);

// model memory limit should be <= 99mb
const {
Expand Down
32 changes: 18 additions & 14 deletions x-pack/test/functional/services/ml/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,19 @@ export function MachineLearningAPIProvider({ getService }: FtrProviderContext) {
return jobStats;
},

async waitForJobState(jobId: string, expectedJobState: JOB_STATE) {
await retry.waitForWithTimeout(
`job state to be ${expectedJobState}`,
2 * 60 * 1000,
async () => {
const state = await this.getJobState(jobId);
if (state === expectedJobState) {
return true;
} else {
throw new Error(`expected job state to be ${expectedJobState} but got ${state}`);
}
async waitForJobState(
jobId: string,
expectedJobState: JOB_STATE,
timeout: number = 2 * 60 * 1000
) {
await retry.waitForWithTimeout(`job state to be ${expectedJobState}`, timeout, async () => {
const state = await this.getJobState(jobId);
if (state === expectedJobState) {
return true;
} else {
throw new Error(`expected job state to be ${expectedJobState} but got ${state}`);
}
);
});
},

async getDatafeedState(datafeedId: string): Promise<DATAFEED_STATE> {
Expand All @@ -214,10 +214,14 @@ export function MachineLearningAPIProvider({ getService }: FtrProviderContext) {
return state;
},

async waitForDatafeedState(datafeedId: string, expectedDatafeedState: DATAFEED_STATE) {
async waitForDatafeedState(
datafeedId: string,
expectedDatafeedState: DATAFEED_STATE,
timeout: number = 2 * 60 * 1000
) {
await retry.waitForWithTimeout(
`datafeed state to be ${expectedDatafeedState}`,
2 * 60 * 1000,
timeout,
async () => {
const state = await this.getDatafeedState(datafeedId);
if (state === expectedDatafeedState) {
Expand Down

0 comments on commit b702a61

Please sign in to comment.