Skip to content
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

[AppServices] Fix unhandled promise rejections in search tests #112849

Conversation

jloleysens
Copy link
Contributor

@jloleysens jloleysens commented Sep 22, 2021

Summary

Partially addresses #112699

How to check

Run the respective files with:

node --unhandled-rejections=strict scripts/jest <path-to-test-file>

Notes

Added catchError to search source test, not sure this is the correct way to ensure that this rejection gets handled?

@jloleysens jloleysens added chore v8.0.0 Team:AppServices release_note:skip Skip the PR/issue when compiling release notes v7.16.0 labels Sep 22, 2021
@jloleysens jloleysens requested a review from a team as a code owner September 22, 2021 15:59
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServices)

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

await searchSource
.fetch$(options)
.pipe(catchError((e) => e))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with this code for a bit hoping to find a solution that was a bit more direct. Why do you need this line when catch is called below? I approve of the PR but wish I understood this a bit better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem in this test is actually a few lines up above:

searchSourceDependencies.search = jest.fn().mockReturnValue(of(Promise.reject('aaaaa')));

The mock search function will throw an uncaught error as soon as fetch$ is called (rather than when it's subscribed to, as the real search function would). In fact, if you keep this line as-is and get rid of the rest of this test, then run the test with the flag, you'll still get the unhandled rejection.

Instead, I think we want to change this line to the following:

searchSourceDependencies.search = jest.fn().mockReturnValue(throwError('aaaaa'));

If we make this change, the rest of the test can remain unchanged and we won't see the given error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a closer look @mattkime , I was also a bit confused! And thanks for the explanation @lukasolson ! I'll update the PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work @lukasolson !

@jloleysens
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jloleysens jloleysens merged commit 7a49851 into elastic:master Sep 28, 2021
@jloleysens jloleysens deleted the appservices/handle-unhandled-promise-rejections-in-jest branch September 28, 2021 13:40
jloleysens added a commit to jloleysens/kibana that referenced this pull request Sep 28, 2021
…ic#112849)

* updated jest tests to avoid generating unhandled promise rejections

* rather use throwError

* remove unused imports

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	src/plugins/data/common/search/search_source/search_source.test.ts
jloleysens added a commit that referenced this pull request Sep 29, 2021
…112849) (#113264)

* [AppServices] Fix unhandled promise rejections in search tests (#112849)

* updated jest tests to avoid generating unhandled promise rejections

* rather use throwError

* remove unused imports

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	src/plugins/data/common/search/search_source/search_source.test.ts

* Fix lint issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore release_note:skip Skip the PR/issue when compiling release notes v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants