Skip to content

Commit 0c95fa3

Browse files
[ML] Forecast api delete test: add retry to ensure forecast has time to complete before deletion (elastic#197111)
## Summary Fixes elastic#195602 This PR adds a retry for 10 seconds to the deleteForecast utility function to ensure the forecast has completed before a deletion attempt is made. Flaky test: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7201 ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
1 parent 0a04e06 commit 0c95fa3

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

x-pack/test/api_integration/apis/ml/anomaly_detectors/forecast_with_spaces.ts

+17-15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default ({ getService }: FtrProviderContext) => {
1515
const supertest = getService('supertestWithoutAuth');
1616
const ml = getService('ml');
1717
const spacesService = getService('spaces');
18+
const retry = getService('retry');
1819

1920
const forecastJobId = 'fq_single_forecast';
2021
const forecastJobDatafeedId = `datafeed-${forecastJobId}`;
@@ -45,21 +46,22 @@ export default ({ getService }: FtrProviderContext) => {
4546
user: USER,
4647
expectedStatusCode: number
4748
) {
48-
const { body, status } = await supertest
49-
.delete(
50-
`${
51-
space ? `/s/${space}` : ''
52-
}/internal/ml/anomaly_detectors/${jobId}/_forecast/${forecastId}`
53-
)
54-
.auth(user, ml.securityCommon.getPasswordForUser(user))
55-
.set(getCommonRequestHeader('1'));
56-
ml.api.assertResponseStatusCode(expectedStatusCode, status, body);
57-
58-
return body;
49+
await retry.tryForTime(10000, async () => {
50+
const { body, status } = await supertest
51+
.delete(
52+
`${
53+
space ? `/s/${space}` : ''
54+
}/internal/ml/anomaly_detectors/${jobId}/_forecast/${forecastId}`
55+
)
56+
.auth(user, ml.securityCommon.getPasswordForUser(user))
57+
.set(getCommonRequestHeader('1'));
58+
ml.api.assertResponseStatusCode(expectedStatusCode, status, body);
59+
60+
return body;
61+
});
5962
}
6063

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

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

116118
it('should delete forecast for user with permissions', async () => {
117-
await await deleteForecast(forecastJobId, forecastId, idSpace1, USER.ML_POWERUSER, 200);
119+
await deleteForecast(forecastJobId, forecastId, idSpace1, USER.ML_POWERUSER, 200);
118120
});
119121

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

0 commit comments

Comments
 (0)