From fa88781319a27a3ce24a458ed4745831f282b81e Mon Sep 17 00:00:00 2001 From: Pete Harverson Date: Fri, 3 Sep 2021 13:10:09 +0100 Subject: [PATCH] [ML] Edits to setup and clean-up steps following review --- .../apis/ml/jobs/force_start_datafeeds.ts | 19 ++++++++++--------- .../ml/jobs/force_start_datafeeds_spaces.ts | 12 +++++++----- .../apis/ml/jobs/stop_datafeeds.ts | 15 ++++++++------- .../apis/ml/jobs/stop_datafeeds_spaces.ts | 16 +++++++++++----- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/x-pack/test/api_integration/apis/ml/jobs/force_start_datafeeds.ts b/x-pack/test/api_integration/apis/ml/jobs/force_start_datafeeds.ts index 6bf260c6551beb..04ab308a0d7b29 100644 --- a/x-pack/test/api_integration/apis/ml/jobs/force_start_datafeeds.ts +++ b/x-pack/test/api_integration/apis/ml/jobs/force_start_datafeeds.ts @@ -23,7 +23,7 @@ export default ({ getService }: FtrProviderContext) => { user: USER, requestBody: object, expectedResponsecode: number - ): Promise { + ): Promise> { const { body } = await supertest .post('/api/ml/jobs/force_start_datafeeds') .auth(user, ml.securityCommon.getPasswordForUser(user)) @@ -115,13 +115,7 @@ export default ({ getService }: FtrProviderContext) => { before(async () => { await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote'); await ml.testResources.setKibanaTimeZoneToUTC(); - }); - - after(async () => { - await ml.api.cleanMlIndices(); - }); - it('sets up jobs', async () => { for (const job of testSetupJobConfigs) { const datafeedId = `datafeed-${job.job_id}`; await ml.api.createAnomalyDetectionJob(job); @@ -133,6 +127,13 @@ export default ({ getService }: FtrProviderContext) => { } }); + after(async () => { + for (const job of testSetupJobConfigs) { + await ml.api.deleteAnomalyDetectionJobES(job.job_id); + } + await ml.api.cleanMlIndices(); + }); + describe('rejects requests for unauthorized users', function () { for (const testData of testDataListUnauthorized) { describe('fails to force start supplied datafeed IDs', function () { @@ -184,7 +185,7 @@ export default ({ getService }: FtrProviderContext) => { // check datafeeds have started for (const id of testData.requestBody.datafeedIds) { - await ml.api.waitForDatafeedState(id, DATAFEED_STATE.STARTED, 4 * 60 * 1000); + await ml.api.waitForDatafeedState(id, DATAFEED_STATE.STARTED); } }); } @@ -215,7 +216,7 @@ export default ({ getService }: FtrProviderContext) => { // check datafeeds are still started for (const id of testData.requestBody.datafeedIds) { - await ml.api.waitForDatafeedState(id, DATAFEED_STATE.STARTED, 4 * 60 * 1000); + await ml.api.waitForDatafeedState(id, DATAFEED_STATE.STARTED); } }); } diff --git a/x-pack/test/api_integration/apis/ml/jobs/force_start_datafeeds_spaces.ts b/x-pack/test/api_integration/apis/ml/jobs/force_start_datafeeds_spaces.ts index 1f7d4e9c315e0f..1ebc6c5b784242 100644 --- a/x-pack/test/api_integration/apis/ml/jobs/force_start_datafeeds_spaces.ts +++ b/x-pack/test/api_integration/apis/ml/jobs/force_start_datafeeds_spaces.ts @@ -33,7 +33,7 @@ export default ({ getService }: FtrProviderContext) => { datafeedIds: string[], start: number, end: number - ) { + ): Promise> { const { body } = await supertest .post(`/s/${space}/api/ml/jobs/force_start_datafeeds`) .auth( @@ -84,6 +84,8 @@ export default ({ getService }: FtrProviderContext) => { afterEach(async () => { await ml.api.closeAnomalyDetectionJob(jobIdSpace1); await ml.api.closeAnomalyDetectionJob(jobIdSpace2); + await ml.api.deleteAnomalyDetectionJobES(jobIdSpace1); + await ml.api.deleteAnomalyDetectionJobES(jobIdSpace2); await ml.api.cleanMlIndices(); await ml.testResources.cleanMLSavedObjects(); }); @@ -96,13 +98,13 @@ export default ({ getService }: FtrProviderContext) => { it('should start single datafeed from same space', async () => { const body = await runRequest(idSpace1, 200, [datafeedIdSpace1], startMs, endMs); expect(body).to.eql({ [datafeedIdSpace1]: { started: true } }); - await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STARTED, 4 * 60 * 1000); + await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STARTED); }); it('should not start single datafeed from different space', async () => { const body = await runRequest(idSpace2, 200, [datafeedIdSpace1], startMs, endMs); expect(body).to.eql({ [datafeedIdSpace1]: { error: 'Job has no datafeed', started: false } }); - await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STOPPED, 4 * 60 * 1000); + await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STOPPED); }); it('should only start datafeed from same space when called with a list of datafeeds', async () => { @@ -117,8 +119,8 @@ export default ({ getService }: FtrProviderContext) => { [datafeedIdSpace1]: { started: true }, [datafeedIdSpace2]: { error: 'Job has no datafeed', started: false }, }); - await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STARTED, 4 * 60 * 1000); - await ml.api.waitForDatafeedState(datafeedIdSpace2, DATAFEED_STATE.STOPPED, 4 * 60 * 1000); + await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STARTED); + await ml.api.waitForDatafeedState(datafeedIdSpace2, DATAFEED_STATE.STOPPED); }); }); }; diff --git a/x-pack/test/api_integration/apis/ml/jobs/stop_datafeeds.ts b/x-pack/test/api_integration/apis/ml/jobs/stop_datafeeds.ts index edcad04c27bd25..593dfdd2fdfe70 100644 --- a/x-pack/test/api_integration/apis/ml/jobs/stop_datafeeds.ts +++ b/x-pack/test/api_integration/apis/ml/jobs/stop_datafeeds.ts @@ -23,7 +23,7 @@ export default ({ getService }: FtrProviderContext) => { user: USER, requestBody: object, expectedResponsecode: number - ): Promise { + ): Promise> { const { body } = await supertest .post('/api/ml/jobs/stop_datafeeds') .auth(user, ml.securityCommon.getPasswordForUser(user)) @@ -109,13 +109,7 @@ export default ({ getService }: FtrProviderContext) => { before(async () => { await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote'); await ml.testResources.setKibanaTimeZoneToUTC(); - }); - - after(async () => { - await ml.api.cleanMlIndices(); - }); - it('sets up jobs', async () => { for (const job of testSetupJobConfigs) { const datafeedId = `datafeed-${job.job_id}`; await ml.api.createAnomalyDetectionJob(job); @@ -130,6 +124,13 @@ export default ({ getService }: FtrProviderContext) => { } }); + after(async () => { + for (const job of testSetupJobConfigs) { + await ml.api.deleteAnomalyDetectionJobES(job.job_id); + } + await ml.api.cleanMlIndices(); + }); + describe('rejects requests for unauthorized users', function () { for (const testData of testDataListUnauthorized) { describe('fails to stop supplied datafeed IDs', function () { diff --git a/x-pack/test/api_integration/apis/ml/jobs/stop_datafeeds_spaces.ts b/x-pack/test/api_integration/apis/ml/jobs/stop_datafeeds_spaces.ts index 4e8308ead371d3..0e1ac038dc962d 100644 --- a/x-pack/test/api_integration/apis/ml/jobs/stop_datafeeds_spaces.ts +++ b/x-pack/test/api_integration/apis/ml/jobs/stop_datafeeds_spaces.ts @@ -25,7 +25,11 @@ export default ({ getService }: FtrProviderContext) => { const datafeedIdSpace1 = `datafeed-${jobIdSpace1}`; const datafeedIdSpace2 = `datafeed-${jobIdSpace2}`; - async function runRequest(space: string, expectedStatusCode: number, datafeedIds: string[]) { + async function runRequest( + space: string, + expectedStatusCode: number, + datafeedIds: string[] + ): Promise> { const { body } = await supertest .post(`/s/${space}/api/ml/jobs/stop_datafeeds`) .auth( @@ -83,6 +87,8 @@ export default ({ getService }: FtrProviderContext) => { afterEach(async () => { await ml.api.closeAnomalyDetectionJob(jobIdSpace1); await ml.api.closeAnomalyDetectionJob(jobIdSpace2); + await ml.api.deleteAnomalyDetectionJobES(jobIdSpace1); + await ml.api.deleteAnomalyDetectionJobES(jobIdSpace2); await ml.api.cleanMlIndices(); await ml.testResources.cleanMLSavedObjects(); }); @@ -95,13 +101,13 @@ export default ({ getService }: FtrProviderContext) => { it('should stop single datafeed from same space', async () => { const body = await runRequest(idSpace1, 200, [datafeedIdSpace1]); expect(body).to.eql({ [datafeedIdSpace1]: { stopped: true } }); - await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STOPPED, 4 * 60 * 1000); + await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STOPPED); }); it('should not stop single datafeed from different space', async () => { const body = await runRequest(idSpace2, 200, [datafeedIdSpace1]); expect(body).to.eql({ [datafeedIdSpace1]: { stopped: false } }); - await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STARTED, 4 * 60 * 1000); + await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STARTED); }); it('should only stop datafeed from same space when called with a list of datafeeds', async () => { @@ -110,8 +116,8 @@ export default ({ getService }: FtrProviderContext) => { [datafeedIdSpace1]: { stopped: true }, [datafeedIdSpace2]: { stopped: false }, }); - await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STOPPED, 4 * 60 * 1000); - await ml.api.waitForDatafeedState(datafeedIdSpace2, DATAFEED_STATE.STARTED, 4 * 60 * 1000); + await ml.api.waitForDatafeedState(datafeedIdSpace1, DATAFEED_STATE.STOPPED); + await ml.api.waitForDatafeedState(datafeedIdSpace2, DATAFEED_STATE.STARTED); }); }); };