Skip to content

Commit

Permalink
[ML] Update dfa delete tests to re-use code
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed May 29, 2020
1 parent f67115d commit 725d56d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default ({ getService }: FtrProviderContext) => {
.expect(200);

expect(body.analyticsJobDeleted.success).to.eql(true);
await ml.api.assertDataFrameAnalyticsJobNotExist(analyticsId);
await ml.api.waitForDataFrameAnalyticsJobNotToExist(analyticsId);
});

it('should not allow to retrieve analytics jobs for unauthorized user', async () => {
Expand All @@ -96,7 +96,7 @@ export default ({ getService }: FtrProviderContext) => {

expect(body.error).to.eql('Not Found');
expect(body.message).to.eql('Not Found');
await ml.api.assertDataFrameAnalyticsJobExist(analyticsId);
await ml.api.waitForDataFrameAnalyticsJobToExist(analyticsId);
});

it('should not allow to retrieve analytics jobs for the user with only view permission', async () => {
Expand All @@ -109,7 +109,7 @@ export default ({ getService }: FtrProviderContext) => {

expect(body.error).to.eql('Not Found');
expect(body.message).to.eql('Not Found');
await ml.api.assertDataFrameAnalyticsJobExist(analyticsId);
await ml.api.waitForDataFrameAnalyticsJobToExist(analyticsId);
});

it('should show 404 error if job does not exist or has already been deleted', async () => {
Expand Down Expand Up @@ -147,7 +147,7 @@ export default ({ getService }: FtrProviderContext) => {
expect(body.analyticsJobDeleted.success).to.eql(true);
expect(body.destIndexDeleted.success).to.eql(true);
expect(body.destIndexPatternDeleted.success).to.eql(false);
await ml.api.assertDataFrameAnalyticsJobNotExist(analyticsId);
await ml.api.waitForDataFrameAnalyticsJobNotToExist(analyticsId);
await ml.api.assertIndicesNotToExist(destinationIndex);
});
});
Expand Down Expand Up @@ -176,7 +176,7 @@ export default ({ getService }: FtrProviderContext) => {
expect(body.analyticsJobDeleted.success).to.eql(true);
expect(body.destIndexDeleted.success).to.eql(false);
expect(body.destIndexPatternDeleted.success).to.eql(true);
await ml.api.assertDataFrameAnalyticsJobNotExist(analyticsId);
await ml.api.waitForDataFrameAnalyticsJobNotToExist(analyticsId);
await ml.testResources.assertIndexPatternNotExist(destinationIndex);
});
});
Expand Down Expand Up @@ -208,7 +208,7 @@ export default ({ getService }: FtrProviderContext) => {
expect(body.analyticsJobDeleted.success).to.eql(true);
expect(body.destIndexDeleted.success).to.eql(true);
expect(body.destIndexPatternDeleted.success).to.eql(true);
await ml.api.assertDataFrameAnalyticsJobNotExist(analyticsId);
await ml.api.waitForDataFrameAnalyticsJobNotToExist(analyticsId);
await ml.api.assertIndicesNotToExist(destinationIndex);
await ml.testResources.assertIndexPatternNotExist(destinationIndex);
});
Expand Down
50 changes: 9 additions & 41 deletions x-pack/test/functional/services/ml/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,7 @@ export function MachineLearningAPIProvider({ getService }: FtrProviderContext) {
.to.have.property('acknowledged')
.eql(true, 'Response for create request indices should be acknowledged.');

await retry.waitForWithTimeout(`'${indices}' indices to be created`, 30 * 1000, async () => {
if ((await es.indices.exists({ index: indices, allowNoIndices: false })) === true) {
return true;
} else {
throw new Error(`expected indices '${indices}' to be created`);
}
});
await this.assertIndicesExist(indices);
},

async deleteIndices(indices: string) {
Expand All @@ -145,13 +139,7 @@ export function MachineLearningAPIProvider({ getService }: FtrProviderContext) {
.to.have.property('acknowledged')
.eql(true, 'Response for delete request should be acknowledged.');

await retry.waitForWithTimeout(`'${indices}' indices to be deleted`, 30 * 1000, async () => {
if ((await es.indices.exists({ index: indices, allowNoIndices: false })) === false) {
return true;
} else {
throw new Error(`expected indices '${indices}' to be deleted`);
}
});
await this.assertIndicesNotToExist(indices);
},

async cleanMlIndices() {
Expand Down Expand Up @@ -440,34 +428,14 @@ export function MachineLearningAPIProvider({ getService }: FtrProviderContext) {
});
},

async assertDataFrameAnalyticsJobExist(analyticsId: string) {
await retry.waitForWithTimeout(
`results for job ${analyticsId} to exist`,
30 * 1000,
async () => {
const job = await esSupertest.get(`/_ml/data_frame/analytics/${analyticsId}`);
if (job.status === 200) {
return true;
} else {
throw new Error(`expected data frame analytics job '${analyticsId}' to exist`);
}
}
);
},

async assertDataFrameAnalyticsJobNotExist(analyticsId: string) {
await retry.waitForWithTimeout(
`results for job ${analyticsId} to not exist`,
30 * 1000,
async () => {
const job = await esSupertest.get(`/_ml/data_frame/analytics/${analyticsId}`);
if (job.status === 404) {
return true;
} else {
throw new Error(`expected results for job '${analyticsId}' to not exist`);
}
async waitForDataFrameAnalyticsJobNotToExist(analyticsId: string) {
await retry.waitForWithTimeout(`'${analyticsId}' not to exist`, 5 * 1000, async () => {
if (await this.getDataFrameAnalyticsJob(analyticsId, 404)) {
return true;
} else {
throw new Error(`expected data frame analytics job '${analyticsId}' not to exist`);
}
);
});
},

async createDataFrameAnalyticsJob(jobConfig: DataFrameAnalyticsConfig) {
Expand Down
18 changes: 11 additions & 7 deletions x-pack/test/functional/services/ml/test_resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ export function MachineLearningTestResourcesProvider({ getService }: FtrProvider
},

async assertIndexPatternNotExist(title: string) {
await retry.waitForWithTimeout(`index pattern'${title}' to not exist`, 5 * 1000, async () => {
const indexPatternId = await this.getIndexPatternId(title);
if (!indexPatternId) {
return true;
} else {
throw new Error(`Index pattern '${title}' should not exist.`);
await retry.waitForWithTimeout(
`index pattern '${title}' to not exist`,
5 * 1000,
async () => {
const indexPatternId = await this.getIndexPatternId(title);
if (!indexPatternId) {
return true;
} else {
throw new Error(`Index pattern '${title}' should not exist.`);
}
}
});
);
},

async createSavedSearch(title: string, body: object): Promise<string> {
Expand Down

0 comments on commit 725d56d

Please sign in to comment.