-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution] Prevent rules table auto-refreshing on window focus when auto-refresh disabled #165250
[Security Solution] Prevent rules table auto-refreshing on window focus when auto-refresh disabled #165250
Conversation
07a2cde
to
1229cb4
Compare
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
@banderror do we want this to be backported to 8.10? |
80375df
to
96bcfb2
Compare
@maximpn I think it would be too late and risky to backport to |
2ac265e
to
e47a4eb
Compare
e47a4eb
to
ce81ec2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested the PR locally, but the changes look straightforward 👍
I have a few comments regarding the changes, though.
refetchOnWindowFocus: isRefreshOn, | ||
refetchOnReconnect: isRefreshOn, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also turn off those refetches when an action is underway?
refetchOnWindowFocus: isRefreshOn, | |
refetchOnReconnect: isRefreshOn, | |
refetchOnWindowFocus: isRefreshOn && !isActionInProgress, | |
refetchOnReconnect: isRefreshOn && !isActionInProgress, |
it('Auto refreshes rules', () => { | ||
mockGlobalClock(); | ||
visitWithoutDateRange(DETECTIONS_RULE_MANAGEMENT_URL); | ||
it('gets disabled when any rule selected and enabled after rules unselected', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('gets disabled when any rule selected and enabled after rules unselected', () => { | |
it('gets deactivated when any rule selected and enabled after rules unselected', () => { |
beforeEach(() => { | ||
mockGlobalClock(); | ||
visitWithoutDateRange(DETECTIONS_RULE_MANAGEMENT_URL); | ||
// waitForPageToBeLoaded(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove any commented code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, most probably it's an artefact of a merge conflict. Removed.
disableAutoRefresh(); | ||
cy.tick(ONE_MINUTE_IN_MS * 2); // Make sure enough time has passed to verify auto-refresh doesn't happen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid placing test steps in the beforeEach
section. That section is designed for preconditions. Even when certain test steps are common across several test cases, it's almost always better to repeat them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you give an explanation why we should avoid it and give examples of preconditions? What in this particular case doesn't correspond to a precondition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed pros and cons with @xcrzx and determined it'd be better to have disableAutoRefresh()
and cy.tick(ONE_MINUTE_IN_MS * 2)
in the test body to improve readability and tests clearness.
// Without a delay here the following expectations pass even it shouldn't happen | ||
// 'focus' event gets handled in async way so the status gets updated with some delay | ||
// eslint-disable-next-line cypress/no-unnecessary-waiting | ||
cy.wait(1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this affecting just a single test case? Do we need to add wait
to other cases too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's required only for the test checking refresh doesn't happen on window focus. I've updated the comment to make clearer.
|
||
// auto refresh should be deactivated (which means disabled without an ability to enable it) after rules selected | ||
expectAutoRefreshIsDeactivated(); | ||
cy.get(REFRESH_RULES_STATUS).should('not.contain', 'Updating...'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is redundant; the next one should suffice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we could control when refresh happens it'd be really redundant. It can catch an updating state though it's not really transparent. I've replaced it with a comment and a custom timeout for the next expectation. Without a custom timeout it waits according the global configuration so enough time can pass after a refresh so an updated state shows Updated 2 minutes ago
and the test passes while it wouldn't catch a problem.
@@ -30,10 +30,9 @@ import { createRule } from '../../../../tasks/api_calls/rules'; | |||
import { cleanKibana } from '../../../../tasks/common'; | |||
import { getNewRule } from '../../../../objects/rule'; | |||
|
|||
const DEFAULT_RULE_REFRESH_INTERVAL_VALUE = 60000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the previous naming. In this context, DEFAULT_RULE_REFRESH_INTERVAL_VALUE
provides more clarity than ONE_MINUTE_IN_MS
Hey @xcrzx, I'm sorry for jumping in, but I think it's important. |
ce81ec2
to
b31bd46
Compare
b31bd46
to
da2d6e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've gone through the comments with @maximpn and discussed the testing practices we use. We've agreed to move the test steps out of the beforeEach
section, so I'm giving this PR a 👍
@banderror: The changes in this PR are quite straightforward. However, I've verified them locally as you requested. Found no issues.
7455a95
to
ef1d8e5
Compare
363328f
to
cc9c0a9
Compare
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @maximpn |
Fixes: #165221
Summary
This PR prevents rules management table from being auto-refreshed on window focus or on reconnect if auto-refresh is disabled.
Before:
Auto-refresh is switched off
Screen.Recording.2023-08-30.at.13.29.41.mov
Auto-refresh is switched off AND a rule is selected
Screen.Recording.2023-08-30.at.13.30.27.mov
After:
Auto-refresh is switched off
Screen.Recording.2023-08-30.at.19.41.51.mov
Auto-refresh is switched off AND a rule is selected
Screen.Recording.2023-08-30.at.19.45.28.mov
Checklist
Delete any items that are not applicable to this PR.
Flaky test runner
rules_table_auto_refresh.cy.ts (150 runs) 🟢