Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Forecast api delete test: add retry to ensure forecast has time to complete before deletion #197111

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertestWithoutAuth');
const ml = getService('ml');
const spacesService = getService('spaces');
const retry = getService('retry');

const forecastJobId = 'fq_single_forecast';
const forecastJobDatafeedId = `datafeed-${forecastJobId}`;
Expand Down Expand Up @@ -45,21 +46,22 @@ export default ({ getService }: FtrProviderContext) => {
user: USER,
expectedStatusCode: number
) {
const { body, status } = await supertest
.delete(
`${
space ? `/s/${space}` : ''
}/internal/ml/anomaly_detectors/${jobId}/_forecast/${forecastId}`
)
.auth(user, ml.securityCommon.getPasswordForUser(user))
.set(getCommonRequestHeader('1'));
ml.api.assertResponseStatusCode(expectedStatusCode, status, body);

return body;
await retry.tryForTime(10000, async () => {
const { body, status } = await supertest
.delete(
`${
space ? `/s/${space}` : ''
}/internal/ml/anomaly_detectors/${jobId}/_forecast/${forecastId}`
)
.auth(user, ml.securityCommon.getPasswordForUser(user))
.set(getCommonRequestHeader('1'));
ml.api.assertResponseStatusCode(expectedStatusCode, status, body);

return body;
});
}

// Failing see: https://github.com/elastic/kibana/issues/195602
describe.skip('POST anomaly_detectors _forecast with spaces', function () {
describe('POST anomaly_detectors _forecast with spaces', function () {
let forecastId: string;
before(async () => {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote');
Expand Down Expand Up @@ -110,11 +112,11 @@ export default ({ getService }: FtrProviderContext) => {
});

it('should not delete forecast for user without permissions', async () => {
await await deleteForecast(forecastJobId, forecastId, idSpace1, USER.ML_VIEWER, 403);
await deleteForecast(forecastJobId, forecastId, idSpace1, USER.ML_VIEWER, 403);
});

it('should delete forecast for user with permissions', async () => {
await await deleteForecast(forecastJobId, forecastId, idSpace1, USER.ML_POWERUSER, 200);
await deleteForecast(forecastJobId, forecastId, idSpace1, USER.ML_POWERUSER, 200);
});

it('should not run forecast for open job with invalid duration', async () => {
Expand Down