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

[BUG] buildPointSeriesData unit test fails due to hard-coded expected value that is not timezone friendly #4865

Closed
evankielley opened this issue Aug 31, 2023 · 2 comments
Assignees
Labels
bug Something isn't working test:unit

Comments

@evankielley
Copy link

Describe the bug
The unit test buildPointSeriesData fails due to trying to match a hard-coded UTC datetime with a datetime generated in accordance with my machine's timezone. A simple fix would be to change the expected values to be moment('2023-01-01') and moment('2023-01-01') instead of '2023-01-01T00:00:00+00:00' and '2023-01-02T00:00:00+00:00'.

To Reproduce
Steps to reproduce the behavior:

  1. Run yarn test:jest src/plugins/discover/public/application/components/chart/utils/point_series.test.ts

Expected behavior
The unit test should pass.

OpenSearch Version
N/A

Dashboards Version
N/A

Plugins
N/A

Screenshots
image

Host/Environment (please complete the following information):

  • OS: macOS 13.5.1
  • Browser and version: N/A

Additional context
yarn version: 1.22.19
node version: v18.16.0

@evankielley evankielley added bug Something isn't working untriaged labels Aug 31, 2023
@ananzh ananzh self-assigned this Sep 12, 2023
@ananzh ananzh removed the untriaged label Sep 12, 2023
@ananzh
Copy link
Member

ananzh commented Sep 12, 2023

@evankielley Thank you for catching this test bug for us and you are absolutely right. I also reproduced and saw the unit test for buildPointSeriesData fails when comparing expected datetime strings. The discrepancy arises from the behavior of the moment library regarding time zones. Specifically, when creating a moment object like moment('2023-01-01'), it uses the local timezone of the machine executing the code. As a result, on a machine set to the -08:00 timezone, the formatted string from the moment object will also carry that -08:00 offset, causing a mismatch with the hard-coded UTC string '2023-01-01T00:00:00+00:00'.

As @evankielley suggested, to ensure consistency across different environments, the date-time strings used within the test should be explicitly defined in UTC. By using a format like moment('2023-01-01T00:00:00Z'), the moment object is set in UTC regardless of the system's local timezone. Thus, when this moment object is formatted, it should consistently produce a UTC timestamp, avoiding discrepancies in different environments.

I will raise a PR to fix it.

ananzh added a commit to ananzh/OpenSearch-Dashboards that referenced this issue Sep 12, 2023
ananzh added a commit to ananzh/OpenSearch-Dashboards that referenced this issue Sep 12, 2023
@evankielley
Copy link
Author

Thanks @ananzh !

opensearch-trigger-bot bot pushed a commit that referenced this issue Sep 15, 2023
…4992)

Issue Resolved
#4865

Signed-off-by: ananzh <[email protected]>
(cherry picked from commit 195417b)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
joshuarrrr pushed a commit that referenced this issue Sep 22, 2023
…4992) (#5031)

Issue Resolved
#4865

Signed-off-by: ananzh <[email protected]>
(cherry picked from commit 195417b)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working test:unit
Projects
None yet
Development

No branches or pull requests

2 participants