From c419f7bf409e3f6faae2c6f8f61fe0c3881dfa34 Mon Sep 17 00:00:00 2001 From: Alexi Doak <109488926+doakalexi@users.noreply.github.com> Date: Mon, 23 Sep 2024 12:09:40 -0700 Subject: [PATCH] =?UTF-8?q?[ResponseOps]=20Flaky=20test=20x-pack/test/aler?= =?UTF-8?q?ting=5Fapi=5Fintegration/spaces=5Fonly/tests/alerting/group2/mo?= =?UTF-8?q?nitoring=C2=B7ts=20(#193614)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves https://github.com/elastic/kibana/issues/193072 ## Summary Removes the skip on flaky monitoring tests (cherry picked from commit cd5ff16dfdbc5ff46199f4ce5785bf52da22fa8a) --- .../tests/alerting/group2/monitoring.ts | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group2/monitoring.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group2/monitoring.ts index a86db4a8c27e4..480150b9a97a6 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group2/monitoring.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group2/monitoring.ts @@ -13,18 +13,28 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context'; // eslint-disable-next-line import/no-default-export export default function monitoringAlertTests({ getService }: FtrProviderContext) { const supertest = getService('supertest'); + const retry = getService('retry'); - // Failing: See https://github.com/elastic/kibana/issues/193072 - describe.skip('monitoring', () => { + describe('monitoring', () => { const objectRemover = new ObjectRemover(supertest); + const run = async (id: string) => { + await retry.try(async () => { + // Sometimes the rule may already be running, which returns a 200. Try until it isn't + const response = await supertest + .post(`${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rule/${id}/_run_soon`) + .set('kbn-xsrf', 'foo'); + expect(response.status).to.eql(204); + }); + }; + after(async () => await objectRemover.removeAll()); it('should return an accurate history for a single success', async () => { const createResponse = await supertest .post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule`) .set('kbn-xsrf', 'foo') - .send(getTestRuleData({ schedule: { interval: '3s' } })); + .send(getTestRuleData({ schedule: { interval: '1h' } })); expect(createResponse.status).to.eql(200); objectRemover.add(Spaces.space1.id, createResponse.body.id, 'rule', 'alerting'); @@ -45,15 +55,21 @@ export default function monitoringAlertTests({ getService }: FtrProviderContext) const createResponse = await supertest .post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule`) .set('kbn-xsrf', 'foo') - .send(getTestRuleData({ schedule: { interval: '3s' } })); + .send(getTestRuleData({ schedule: { interval: '1h' } })); expect(createResponse.status).to.eql(200); - objectRemover.add(Spaces.space1.id, createResponse.body.id, 'rule', 'alerting'); + const ruleId = createResponse.body.id; + objectRemover.add(Spaces.space1.id, ruleId, 'rule', 'alerting'); + + for (let i = 1; i < 3; i++) { + await waitForExecutionCount(i, ruleId); + await run(ruleId); + } // Allow at least three executions - await waitForExecutionCount(3, createResponse.body.id); + await waitForExecutionCount(3, ruleId); const getResponse = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rule/${createResponse.body.id}` + `${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rule/${ruleId}` ); expect(getResponse.status).to.eql(200); @@ -72,20 +88,26 @@ export default function monitoringAlertTests({ getService }: FtrProviderContext) .send( getTestRuleData({ rule_type_id: 'test.patternSuccessOrFailure', - schedule: { interval: '3s' }, + schedule: { interval: '1h' }, params: { pattern, }, }) ); expect(createResponse.status).to.eql(200); - objectRemover.add(Spaces.space1.id, createResponse.body.id, 'rule', 'alerting'); - // Allow at least three executions - await waitForExecutionCount(5, createResponse.body.id); + const ruleId = createResponse.body.id; + objectRemover.add(Spaces.space1.id, ruleId, 'rule', 'alerting'); + + for (let i = 1; i < 5; i++) { + await waitForExecutionCount(i, ruleId); + await run(ruleId); + } + // Allow at least five executions + await waitForExecutionCount(5, ruleId); const getResponse = await supertest.get( - `${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rule/${createResponse.body.id}` + `${getUrlPrefix(Spaces.space1.id)}/internal/alerting/rule/${ruleId}` ); expect(getResponse.status).to.eql(200);