-
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
[Cases] Fix cases flaky tests #176863
[Cases] Fix cases flaky tests #176863
Conversation
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
* `appId` and `appTitle` are dynamically retrieved from kibana context. | ||
* We need to update the state if any of these values change, the rest of props are never updated. | ||
*/ | ||
useEffect(() => { |
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.
Removing the useEffect
s to save re-render in the hope of making tests more resilient as all of them rely on the CasesProvider
. Also, they are redundant.
@@ -41,7 +41,6 @@ const initialCaseValue: FormProps = { | |||
connectorId: NONE_CONNECTOR_ID, | |||
fields: null, | |||
syncAlerts: true, | |||
selectedOwner: null, |
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.
The default value is set by the component that renders the solution selection.
@@ -61,16 +61,6 @@ const OwnerSelector = ({ | |||
|
|||
const onChange = useCallback((val: string) => field.setValue(val), [field]); | |||
|
|||
useEffect(() => { |
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.
Redundant. defaultValue
can produce the same results.
@@ -20,33 +20,38 @@ interface Props { | |||
isLoading: boolean; | |||
} | |||
|
|||
const SeverityFieldFormComponent = ({ isLoading }: { isLoading: boolean }) => { |
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.
Moved inside UseField
and remove all the watch
logic.
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.
Nice refactoring 👍
Should we loop all tests just to verify once?
Good point. Added here |
externalReferenceAttachmentTypeRegistry, | ||
features, | ||
owner, | ||
permissions, |
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.
Did you end up checking if this was fine for the permissions? useMemo
only uses Object.is
for comparisons.
Edit: after reading the PR further I think this might be fine. It seems all we cared about here seemed to be whether or not the permissions
were null
.
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 think is fine as it is at the moment. If we see unnecessary renders we can optimize further.
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 am ok with leaving it at is but just wanted to highlight that
If we see unnecessary renders we can optimize further.
The issue is rather the permission changing in a way that does not trigger a rerender when it should be cause we only look for superficial changes to the permissions object.
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 see what you mean. This could happen if someone does permissions.create = true
instead of replacing the whole object. Also, most applications initiate the ContextProvider with the permissions being returned by our own helper function here https://github.com/elastic/kibana/blob/56887ac1f85dd06bf89453637eb1a0fb562a43b9/x-pack/plugins/cases/public/client/helpers/can_use_cases.ts. The function will always return a new object. Given all that, you are right. Let's take this into account and make it more explicit.
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.
Done in a70ae15
(#176863)
@@ -34,12 +33,12 @@ describe.skip('UserToolTip', () => { | |||
</UserToolTip> | |||
); | |||
|
|||
fireEvent.mouseOver(screen.getByText('case user')); | |||
fireEvent.mouseOver(await screen.findByText('case user')); |
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.
nit: userEvent
is the recommended class but I wonder if it takes some extra milliseconds so I don't mind keeping fireEvent
.
@@ -148,8 +137,8 @@ export const CasesProvider: React.FC<{ value: CasesContextProps }> = ({ | |||
[getFilesClient, owner] | |||
); | |||
|
|||
return isCasesContextValue(value) ? ( |
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.
In the end, what needed to be changed to remove this check?
I hadn't realized before that isCasesContextValue
also checked for value.permissions != null
.
Missing appId
or appTitle
might be ok but can't this have worse consequences when rendering cases?
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.
In the end, what needed to be changed to remove this check?
Some changes in the PR take into account undefined appId
, mostly in navigation and when we construct the local storage keys. In practice, the appId
will never be undefined
when the cases app is rendered.
I hadn't realized before that isCasesContextValue also checked for value.permissions != null
The permissions
is coming as a prop and it is required. I am not sure why we had the check but it will never be undefined
.
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.
Looks good, Great cleanup 🎉
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @cnasikas |
## Summary PR #176863 improved the cases context provided which we assumed caused some flakiness in our tests. I am unskipping a couple of tests to test if the changes on that PR stabilized the tests. Fixes #176805 Fixes #174528 Fixes #174527 Fixes #174526 Fixes #174525 Fixes #176600 Fixes #146394 ### Checklist Delete any items that are not applicable to this PR. - [x] [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 ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
This reverts commit cf942f2.
## Summary With the help of @umbopepato, @js-jankisalvi, and @adcoelho, we realized that one possible source of flakiness is the `CasesContextProvider` that every test uses under the hood. In this PR I refactor the `CasesContextProvider` to render immediately its children and not wait for the `appId` and `appTitle` to be defined. I make them optional and make all changes needed in the code to accommodate the presence of an optional `appId`. Also, I refactored some components that I believed could introduce flakiness. ## Issues Fixes elastic#175570 Fixes elastic#175956 Fixes elastic#175935 Fixes elastic#175934 Fixes elastic#175655 Fixes elastic#176643 Fixes elastic#175204 Flaky test runner: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5255, https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5261, https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5264, https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5267 ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenario ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: Umberto Pepato <[email protected]> Co-authored-by: kibanamachine <[email protected]>
## Summary PR elastic#176863 improved the cases context provided which we assumed caused some flakiness in our tests. I am unskipping a couple of tests to test if the changes on that PR stabilized the tests. Fixes elastic#176805 Fixes elastic#174528 Fixes elastic#174527 Fixes elastic#174526 Fixes elastic#174525 Fixes elastic#176600 Fixes elastic#146394 ### Checklist Delete any items that are not applicable to this PR. - [x] [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 ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
…177611) ## Summary As a follow-up to elastic#176863 unskipping filterPopOver and propertyActions tests Fixes elastic#176679 Fixes elastic#176680 Fixes elastic#176681 Fixes elastic#176682 Fixes elastic#176683 Fixes elastic#176684 Fixes elastic#176685 Fixes elastic#176686 Fixes elastic#174384 Fixes elastic#174667 Fixes elastic#175310
## Summary As a follow-up to elastic#176863 I am unskipping these severity tests to check if the changes on that PR stabilized them. Fixes elastic#176336
This reverts commit 0dd21e5.
## Summary This reverts commit cf942f2. It also moves the `appId` and `appTitle` outside the cases context. The `useApplication` hook is used when needed to get the `appId` and `appTitle`. Lastly, a new hook called `useCasesLocalStorage` was created to be used when interacting with the local storage. It will use the `owner` to namespace the keys of the local storage and fallback to the `appId` if the `owner` is empty. Fixes #175204 Fixes #175570 ### Checklist Delete any items that are not applicable to this PR. - [x] [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 ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: Kibana Machine <[email protected]>
Summary
With the help of @umbopepato, @js-jankisalvi, and @adcoelho, we realized that one possible source of flakiness is the
CasesContextProvider
that every test uses under the hood. In this PR I refactor theCasesContextProvider
to render immediately its children and not wait for theappId
andappTitle
to be defined. I make them optional and make all changes needed in the code to accommodate the presence of an optionalappId
. Also, I refactored some components that I believed could introduce flakiness.Issues
Fixes #175570
Fixes #175956
Fixes #175935
Fixes #175934
Fixes #175655
Fixes #176643
Fixes #175204
Flaky test runner: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5255, https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5261, https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5264, https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5267
Checklist
Delete any items that are not applicable to this PR.
For maintainers