From 51ac51fa2b0b982421fbbe70a02f1eeb63154f4a Mon Sep 17 00:00:00 2001 From: Ying Mao Date: Tue, 12 Nov 2024 20:44:24 -0500 Subject: [PATCH] Fixing flaky tests (#199562) Resolves https://github.com/elastic/kibana/issues/196226 Resolves https://github.com/elastic/kibana/issues/197352 Resolves https://github.com/elastic/kibana/issues/198631 Resolves https://github.com/elastic/kibana/issues/199722 Resolves https://github.com/elastic/kibana/issues/199351 Resolves https://github.com/elastic/kibana/issues/199580 ## Summary * Fixes flaky `find` test that relied on relative dates to use a fixed offset in the find query params. This closes multiple issues because it is a security and spaces test that uses the same test for different user/space scenarios * Fixes flaky `schedule` test that was checking AAD on an `ad_hoc_run_param` object after backfill was complete and the SO was completed. Added artificial delay to rule execution so the backfill doesn't run as quickly. Co-authored-by: Elastic Machine --- .../common/plugins/alerts/server/rule_types.ts | 3 +++ .../group1/tests/alerting/backfill/find.ts | 10 +++------- .../group1/tests/alerting/backfill/schedule.ts | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/x-pack/test/alerting_api_integration/common/plugins/alerts/server/rule_types.ts b/x-pack/test/alerting_api_integration/common/plugins/alerts/server/rule_types.ts index 6c16c694bc9e9..a3f0f39e908ed 100644 --- a/x-pack/test/alerting_api_integration/common/plugins/alerts/server/rule_types.ts +++ b/x-pack/test/alerting_api_integration/common/plugins/alerts/server/rule_types.ts @@ -750,6 +750,9 @@ function getPatternFiringAutoRecoverFalseRuleType() { } else if (scheduleByPattern === 'timeout') { // delay longer than the timeout await new Promise((r) => setTimeout(r, 12000)); + } else if (scheduleByPattern === 'run_long') { + // delay so rule runs a little longer + await new Promise((r) => setTimeout(r, 4000)); } else { services.alertFactory.create(instanceId).scheduleActions('default', scheduleByPattern); } diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/backfill/find.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/backfill/find.ts index 14ec909ea872d..61df6247b18bb 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/backfill/find.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/backfill/find.ts @@ -17,8 +17,7 @@ export default function findBackfillTests({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const supertestWithoutAuth = getService('supertestWithoutAuth'); - // Failing: See https://github.com/elastic/kibana/issues/196226 - describe.skip('find backfill', () => { + describe('find backfill', () => { let backfillIds: Array<{ id: string; spaceId: string }> = []; const objectRemover = new ObjectRemover(supertest); const start1 = moment().utc().startOf('day').subtract(14, 'days').toISOString(); @@ -279,15 +278,12 @@ export default function findBackfillTests({ getService }: FtrProviderContext) { .auth(apiOptions.username, apiOptions.password); // find backfill with end time that is after one backfill ends + const findEnd = moment(end2).utc().add(1, 'hour').toISOString(); const findWithEndOneRuleResponse = await supertestWithoutAuth .post( `${getUrlPrefix( apiOptions.spaceId - )}/internal/alerting/rules/backfill/_find?end=${moment() - .utc() - .startOf('day') - .subtract(9, 'days') - .toISOString()}` + )}/internal/alerting/rules/backfill/_find?end=${findEnd}` ) .set('kbn-xsrf', 'foo') .auth(apiOptions.username, apiOptions.password); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/backfill/schedule.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/backfill/schedule.ts index 9d7b79d6cbce0..ab4734239ce0d 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/backfill/schedule.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/backfill/schedule.ts @@ -63,7 +63,7 @@ export default function scheduleBackfillTests({ getService }: FtrProviderContext rule_type_id: 'test.patternFiringAutoRecoverFalse', params: { pattern: { - instance: [true, false, true], + instance: ['run_long', 'run_long', 'run_long'], }, }, schedule: { interval: '12h' }, @@ -85,7 +85,7 @@ export default function scheduleBackfillTests({ getService }: FtrProviderContext expect(result.rule.tags).to.eql(['foo']); expect(result.rule.params).to.eql({ pattern: { - instance: [true, false, true], + instance: ['run_long', 'run_long', 'run_long'], }, }); expect(result.rule.enabled).to.eql(true); @@ -103,7 +103,7 @@ export default function scheduleBackfillTests({ getService }: FtrProviderContext expect(result.rule.tags).to.eql(['foo']); expect(result.rule.params).to.eql({ pattern: { - instance: [true, false, true], + instance: ['run_long', 'run_long', 'run_long'], }, }); expect(result.rule.enabled).to.eql(true);