From 7e51b015e16dd3ddfbae904fbb5778f529fa4f37 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 2 Nov 2021 10:49:50 -0500 Subject: [PATCH] [ML] Update tests to use bulk api --- .../anomaly_embeddables_migration.ts | 19 ++++++++----------- .../functional/services/ml/test_resources.ts | 19 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/x-pack/test/functional/apps/ml/embeddables/anomaly_embeddables_migration.ts b/x-pack/test/functional/apps/ml/embeddables/anomaly_embeddables_migration.ts index e3321ddc93f3a..a7fcfa1b83475 100644 --- a/x-pack/test/functional/apps/ml/embeddables/anomaly_embeddables_migration.ts +++ b/x-pack/test/functional/apps/ml/embeddables/anomaly_embeddables_migration.ts @@ -13,6 +13,7 @@ const testDataList = [ type: ML_EMBEDDABLE_TYPES.ANOMALY_SWIMLANE, panelTitle: 'ML anomaly swim lane', dashboardSavedObject: { + type: 'dashboard', attributes: { title: `7.15.2 ML anomaly swimlane dashboard ${Date.now()}`, description: '', @@ -36,6 +37,7 @@ const testDataList = [ type: ML_EMBEDDABLE_TYPES.ANOMALY_CHARTS, panelTitle: 'ML anomaly charts', dashboardSavedObject: { + type: 'dashboard', attributes: { title: `7.15.2 ML anomaly charts dashboard ${Date.now()}`, description: '', @@ -73,6 +75,11 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await ml.securityUI.loginAsMlPowerUser(); await ml.api.createAndRunAnomalyDetectionLookbackJob(JOB_CONFIG, DATAFEED_CONFIG); + // Using bulk API because create API might return 400 for conflict errors + await ml.testResources.createBulkSavedObjects( + testDataList.map((d) => d.dashboardSavedObject) + ); + await PageObjects.common.navigateToApp('dashboard'); }); @@ -82,13 +89,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { for (const testData of testDataList) { const { dashboardSavedObject, panelTitle, type } = testData; - describe(`loads saved dashboard from version ${dashboardSavedObject.coreMigrationVersion}`, function () { + describe(`for ${panelTitle}`, function () { before(async () => { - await ml.testResources.createDashboardSavedObject( - dashboardSavedObject.attributes.title, - dashboardSavedObject, - true - ); await PageObjects.common.navigateToApp('dashboard'); }); @@ -100,11 +102,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await PageObjects.dashboard.loadSavedDashboard(dashboardSavedObject.attributes.title); await ml.dashboardEmbeddables.assertDashboardPanelExists(panelTitle); - await PageObjects.timePicker.setAbsoluteRange( - 'Feb 7, 2015 @ 00:00:00.000', - 'Feb 11, 2016 @ 00:00:00.000' - ); - await PageObjects.timePicker.pauseAutoRefresh(); if (type === ML_EMBEDDABLE_TYPES.ANOMALY_CHARTS) { await ml.dashboardEmbeddables.assertAnomalyChartsSeverityThresholdControlExists(); diff --git a/x-pack/test/functional/services/ml/test_resources.ts b/x-pack/test/functional/services/ml/test_resources.ts index 01aa60c0ed9e0..53223a68c9329 100644 --- a/x-pack/test/functional/services/ml/test_resources.ts +++ b/x-pack/test/functional/services/ml/test_resources.ts @@ -128,21 +128,18 @@ export function MachineLearningTestResourcesProvider({ getService }: FtrProvider return createResponse.id; }, - async createDashboardSavedObject( - title: string, - body: object, - override = false - ): Promise { - log.debug(`Creating dashboard with title '${title}'`); + async createBulkSavedObjects(body: object[]): Promise { + log.debug(`Creating bulk saved objects'`); const createResponse = await supertest - .post(`/api/saved_objects/${SavedObjectType.DASHBOARD}?overwrite=${override}`) + .post(`/api/saved_objects/_bulk_create`) .set(COMMON_REQUEST_HEADERS) .send(body) + .expect(200) .then((res: any) => res.body); - log.debug(` > Created with id '${createResponse.id}'`); - return createResponse.id; + log.debug(` > Created bulk saved objects'`); + return createResponse; }, async createIndexPatternIfNeeded(title: string, timeFieldName?: string): Promise { @@ -175,11 +172,11 @@ export function MachineLearningTestResourcesProvider({ getService }: FtrProvider return createResponse.id; }, - async createDashboard(title: string, body: object): Promise { + async createDashboard(title: string, body: object, override = false): Promise { log.debug(`Creating dashboard with title '${title}'`); const createResponse = await supertest - .post(`/api/saved_objects/${SavedObjectType.DASHBOARD}`) + .post(`/api/saved_objects/${SavedObjectType.DASHBOARD}?override=${override}`) .set(COMMON_REQUEST_HEADERS) .send(body) .expect(200)