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

[Test] Fix console error in search_service.test.ts  #595

Merged
merged 1 commit into from
Jul 26, 2021

Conversation

ananzh
Copy link
Member

@ananzh ananzh commented Jul 8, 2021

Description

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.

Signed-off-by: Anan Zhuang ananzh@amazon.com

Issues Resolved

#594

Test results

yarn test:jest /home/anan/work/OpenSearch-Dashboards/src/plugins/data/server/search/search_service.test.ts
yarn run v1.22.5
$ node scripts/jest /home/anan/work/OpenSearch-Dashboards/src/plugins/data/server/search/search_service.test.ts
 PASS  src/plugins/data/server/search/search_service.test.ts
  Search service
    setup()
      ✓ exposes proper contract (43 ms)
    start()
      ✓ exposes proper contract (25 ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        2.961 s
Ran all test suites matching /\/home\/anan\/work\/OpenSearch-Dashboards\/src\/plugins\/data\/server\/search\/search_service.test.ts/i.
Done in 5.36s.

Overall test result:
Screen Shot 2021-07-08 at 10 53 42 AM

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

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>
@ananzh ananzh requested review from tmarkley and kavilla July 8, 2021 17:54
@ananzh ananzh self-assigned this Jul 8, 2021
@opensearch-ci-bot
Copy link
Collaborator

✅   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) {
Copy link
Member

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?

Copy link
Member Author

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?

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 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.

@kavilla kavilla self-requested a review July 21, 2021 23:26
@ananzh ananzh requested a review from boktorbb July 23, 2021 15:38
Copy link
Contributor

@boktorbb boktorbb left a 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

@ananzh ananzh merged commit 2b5b672 into opensearch-project:main Jul 26, 2021
ananzh added a commit to ananzh/OpenSearch-Dashboards that referenced this pull request Jul 26, 2021
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>
ananzh added a commit that referenced this pull request Jul 26, 2021
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>
@ananzh ananzh deleted the i-594 branch February 23, 2022 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants