-
Notifications
You must be signed in to change notification settings - Fork 869
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
[Test] Fix console error in search_service.test.ts #595
Conversation
Run unit test suite search_service.test.ts has a console error: ``` UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'aggs' of undefined ``` This is caused by a missing promise result check in the setup fun in search_service.ts. If the promise result is empty (or null/undefined), then any properties of the empty result is undefined. In our case, `aggs` in `if (value.search.aggs.shardDelay.enabled)` is undefined. In this PR, we fixed this issue by adding a value check in setup fun. Issues resolved: opensearch-project#594 Signed-off-by: Anan Zhuang <ananzh@amazon.com>
✅ DCO Check Passed 2a0cf8e |
@@ -140,7 +140,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> { | |||
.pipe(first()) | |||
.toPromise() | |||
.then((value) => { | |||
if (value.search.aggs.shardDelay.enabled) { |
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 always undefined? if so it's not an error right otherwise could this conditional be completely removed?
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 agree with you that if value.search.aggs.shardDelay.enabled
is always undefined, then removed this completely. But the question is how can we know it is always undefined?
src/plugins/data/server/search/search_service.ts
does have value
tested as null therefore value.search.aggs
is undefined. I am not sure whether in real application usage, value
or value.search
will always be undefined or not, so I just add conditional check for each one. I think that is more logically restrict. What do you think?
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 it's fine but almost would prefer to have a TODO here to figure if this is always undefined then merge in your current fix to unblock us.
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. I agree with Rocky's comment
Run unit test suite search_service.test.ts has a console error: ``` UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'aggs' of undefined ``` This is caused by a missing promise result check in the setup fun in search_service.ts. If the promise result is empty (or null/undefined), then any properties of the empty result is undefined. In our case, `aggs` in `if (value.search.aggs.shardDelay.enabled)` is undefined. In this PR, we fixed this issue by adding a value check in setup fun. Issues resolved: opensearch-project#594 Backport PR: opensearch-project#595 Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Run unit test suite search_service.test.ts has a console error: ``` UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'aggs' of undefined ``` This is caused by a missing promise result check in the setup fun in search_service.ts. If the promise result is empty (or null/undefined), then any properties of the empty result is undefined. In our case, `aggs` in `if (value.search.aggs.shardDelay.enabled)` is undefined. In this PR, we fixed this issue by adding a value check in setup fun. Issues resolved: #594 Backport PR: #595 Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Description
Run unit test suite search_service.test.ts has a console error:
This is caused by a missing promise result check in the setup fun
in search_service.ts. If the promise result is empty (or null/undefined),
then any properties of the empty result is undefined. In our case,
aggs
inif (value.search.aggs.shardDelay.enabled)
is undefined.In this PR, we fixed this issue by adding a value check in setup fun.
Signed-off-by: Anan Zhuang ananzh@amazon.com
Issues Resolved
#594
Test results
Overall test result:
Check List