Skip to content

Commit

Permalink
adding space tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Sep 29, 2022
1 parent 59b74b9 commit 493b68a
Showing 1 changed file with 83 additions and 3 deletions.
86 changes: 83 additions & 3 deletions x-pack/test/api_integration/apis/ml/jobs/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertestWithoutAuth');
const ml = getService('ml');

const idSpace1 = 'space1';

const testSetupJobConfigs = [SINGLE_METRIC_JOB_CONFIG, MULTI_METRIC_JOB_CONFIG];

const testSetupJobConfigsWithSpace = [
{ ...SINGLE_METRIC_JOB_CONFIG, job_id: `${SINGLE_METRIC_JOB_CONFIG.job_id}-${idSpace1}` },
];

const testCalendarsConfigs = [
{
calendar_id: `test_get_cal_1`,
Expand All @@ -40,10 +46,12 @@ export default ({ getService }: FtrProviderContext) => {
async function runGetJobsRequest(
user: USER,
requestBody: object,
expectedResponsecode: number
expectedResponsecode: number,
space?: string
): Promise<CombinedJobWithStats[]> {
const path = space === undefined ? '/api/ml/jobs/jobs' : `/s/${space}/api/ml/jobs/jobs`;
const { body, status } = await supertest
.post('/api/ml/jobs/jobs')
.post(path)
.auth(user, ml.securityCommon.getPasswordForUser(user))
.set(COMMON_REQUEST_HEADERS)
.send(requestBody);
Expand Down Expand Up @@ -71,6 +79,17 @@ export default ({ getService }: FtrProviderContext) => {
},
];

const expectedJobPropertiesWithSpace = [
{
jobId: `${SINGLE_METRIC_JOB_CONFIG.job_id}-${idSpace1}`,
datafeedId: `datafeed-${SINGLE_METRIC_JOB_CONFIG.job_id}-${idSpace1}`,
calendarIds: undefined,
groups: ['farequote', 'automated', 'single-metric'],
modelBytes: 0,
datafeedTotalSearchTimeMs: 0,
},
];

describe('get combined jobs with stats', function () {
before(async () => {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote');
Expand All @@ -85,6 +104,18 @@ export default ({ getService }: FtrProviderContext) => {
});
}

for (const job of testSetupJobConfigsWithSpace) {
await ml.api.createAnomalyDetectionJob(job, idSpace1);
await ml.api.createDatafeed(
{
...DATAFEED_CONFIG,
datafeed_id: `datafeed-${job.job_id}`,
job_id: job.job_id,
},
idSpace1
);
}

for (const cal of testCalendarsConfigs) {
await ml.api.createCalendar(cal.calendar_id, cal);
}
Expand All @@ -94,9 +125,14 @@ export default ({ getService }: FtrProviderContext) => {
await ml.api.cleanMlIndices();
});

it('returns expected list of combined jobs with stats', async () => {
it('returns expected list of combined jobs with stats in default space', async () => {
const jobs = await runGetJobsRequest(USER.ML_VIEWER, {}, 200);

expect(jobs.length).to.eql(
testSetupJobConfigs.length,
`number of jobs in default space should be ${testSetupJobConfigs.length})`
);

jobs.forEach((job, i) => {
expect(job.job_id).to.eql(
expectedJobProperties[i].jobId,
Expand Down Expand Up @@ -126,5 +162,49 @@ export default ({ getService }: FtrProviderContext) => {
);
});
});

it('returns expected list of combined jobs with stats in specified space', async () => {
const jobs = await runGetJobsRequest(USER.ML_VIEWER, {}, 200, idSpace1);

expect(jobs.length).to.eql(
testSetupJobConfigsWithSpace.length,
`number of jobs in default space should be ${testSetupJobConfigsWithSpace.length})`
);

jobs.forEach((job, i) => {
expect(job.job_id).to.eql(
expectedJobPropertiesWithSpace[i].jobId,
`job id should be equal to ${JSON.stringify(expectedJobPropertiesWithSpace[i].jobId)})`
);
expect(job.datafeed_config.datafeed_id).to.eql(
expectedJobPropertiesWithSpace[i].datafeedId,
`datafeed id should be equal to ${JSON.stringify(
expectedJobPropertiesWithSpace[i].datafeedId
)})`
);
expect(job.calendars).to.eql(
expectedJobPropertiesWithSpace[i].calendarIds,
`calendars should be equal to ${JSON.stringify(
expectedJobPropertiesWithSpace[i].calendarIds
)})`
);
expect(job.groups).to.eql(
expectedJobPropertiesWithSpace[i].groups,
`groups should be equal to ${JSON.stringify(expectedJobPropertiesWithSpace[i].groups)})`
);
expect(job.model_size_stats.model_bytes).to.eql(
expectedJobPropertiesWithSpace[i].modelBytes,
`model_bytes should be equal to ${JSON.stringify(
expectedJobPropertiesWithSpace[i].modelBytes
)})`
);
expect(job.datafeed_config.timing_stats.total_search_time_ms).to.eql(
expectedJobPropertiesWithSpace[i].datafeedTotalSearchTimeMs,
`datafeed total_search_time_ms should be equal to ${JSON.stringify(
expectedJobPropertiesWithSpace[i].datafeedTotalSearchTimeMs
)})`
);
});
});
});
};

0 comments on commit 493b68a

Please sign in to comment.