Skip to content

Commit

Permalink
[ML] Update tests to use bulk api
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Nov 2, 2021
1 parent c32274c commit 7e51b01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand All @@ -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: '',
Expand Down Expand Up @@ -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');
});

Expand All @@ -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');
});

Expand All @@ -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();
Expand Down
19 changes: 8 additions & 11 deletions x-pack/test/functional/services/ml/test_resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,18 @@ export function MachineLearningTestResourcesProvider({ getService }: FtrProvider
return createResponse.id;
},

async createDashboardSavedObject(
title: string,
body: object,
override = false
): Promise<string> {
log.debug(`Creating dashboard with title '${title}'`);
async createBulkSavedObjects(body: object[]): Promise<string> {
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<string> {
Expand Down Expand Up @@ -175,11 +172,11 @@ export function MachineLearningTestResourcesProvider({ getService }: FtrProvider
return createResponse.id;
},

async createDashboard(title: string, body: object): Promise<string> {
async createDashboard(title: string, body: object, override = false): Promise<string> {
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)
Expand Down

0 comments on commit 7e51b01

Please sign in to comment.