Skip to content

Commit

Permalink
[8.x] Fixing flaky tests (#199562) (#199897)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [Fixing flaky tests
(#199562)](#199562)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Ying
Mao","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-13T01:44:24Z","message":"Fixing
flaky tests (#199562)\n\nResolves
https://github.com/elastic/kibana/issues/196226\r\nResolves
https://github.com/elastic/kibana/issues/197352\r\nResolves
https://github.com/elastic/kibana/issues/198631\r\nResolves
https://github.com/elastic/kibana/issues/199722\r\nResolves
https://github.com/elastic/kibana/issues/199351\r\nResolves
https://github.com/elastic/kibana/issues/199580\r\n\r\n##
Summary\r\n\r\n* Fixes flaky `find` test that relied on relative dates
to use a fixed\r\noffset in the find query params. This closes multiple
issues because it\r\nis a security and spaces test that uses the same
test for different\r\nuser/space scenarios\r\n* Fixes flaky `schedule`
test that was checking AAD on an\r\n`ad_hoc_run_param` object after
backfill was complete and the SO was\r\ncompleted. Added artificial
delay to rule execution so the backfill\r\ndoesn't run as
quickly.\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"51ac51fa2b0b982421fbbe70a02f1eeb63154f4a","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Alerting","release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.17.0"],"title":"Fixing
flaky
tests","number":199562,"url":"https://github.com/elastic/kibana/pull/199562","mergeCommit":{"message":"Fixing
flaky tests (#199562)\n\nResolves
https://github.com/elastic/kibana/issues/196226\r\nResolves
https://github.com/elastic/kibana/issues/197352\r\nResolves
https://github.com/elastic/kibana/issues/198631\r\nResolves
https://github.com/elastic/kibana/issues/199722\r\nResolves
https://github.com/elastic/kibana/issues/199351\r\nResolves
https://github.com/elastic/kibana/issues/199580\r\n\r\n##
Summary\r\n\r\n* Fixes flaky `find` test that relied on relative dates
to use a fixed\r\noffset in the find query params. This closes multiple
issues because it\r\nis a security and spaces test that uses the same
test for different\r\nuser/space scenarios\r\n* Fixes flaky `schedule`
test that was checking AAD on an\r\n`ad_hoc_run_param` object after
backfill was complete and the SO was\r\ncompleted. Added artificial
delay to rule execution so the backfill\r\ndoesn't run as
quickly.\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"51ac51fa2b0b982421fbbe70a02f1eeb63154f4a"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199562","number":199562,"mergeCommit":{"message":"Fixing
flaky tests (#199562)\n\nResolves
https://github.com/elastic/kibana/issues/196226\r\nResolves
https://github.com/elastic/kibana/issues/197352\r\nResolves
https://github.com/elastic/kibana/issues/198631\r\nResolves
https://github.com/elastic/kibana/issues/199722\r\nResolves
https://github.com/elastic/kibana/issues/199351\r\nResolves
https://github.com/elastic/kibana/issues/199580\r\n\r\n##
Summary\r\n\r\n* Fixes flaky `find` test that relied on relative dates
to use a fixed\r\noffset in the find query params. This closes multiple
issues because it\r\nis a security and spaces test that uses the same
test for different\r\nuser/space scenarios\r\n* Fixes flaky `schedule`
test that was checking AAD on an\r\n`ad_hoc_run_param` object after
backfill was complete and the SO was\r\ncompleted. Added artificial
delay to rule execution so the backfill\r\ndoesn't run as
quickly.\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"51ac51fa2b0b982421fbbe70a02f1eeb63154f4a"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Ying Mao <[email protected]>
  • Loading branch information
kibanamachine and ymao1 authored Nov 13, 2024
1 parent db3f6f2 commit 73376fc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 73376fc

Please sign in to comment.