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

Improve robustness in Dates/conversions test #49086

Merged
merged 2 commits into from
Mar 23, 2023
Merged

Conversation

Keno
Copy link
Member

@Keno Keno commented Mar 21, 2023

In [1], this test was observed to fail, with a 1 second pause between the two Dates.now calls. In general, particularly on high-load CI systems, we cannot make assumptions that calls will complete within any particular amount of time. Instead, we should be asserting properties that should be universally true. This test wants to assert that Dates.now() and Dates.now(UTC) give the same answer if the TZ environment variable is set appropriately, but of course we can't guarantee that these calls run at the same time. Rather than setting an arbitrary limit of 1 second, just run Dates.now again. Our semantics guarantee ordering of these calls (in the absence of leap days/seconds at least), so the test is more robust.

[1] https://buildkite.com/julialang/julia-master/builds/22064#0186ff11-f07e-4ba4-9b54-21bdf738d35e

In [1], this test was observed to fail, with a 1 second pause between
the two Dates.now calls. In general, particularly on high-load CI
systems, we cannot make assumptions that calls will complete within
any particular amount of time. Instead, we should be asserting
properties that should be universally true. This test wants to
assert that Dates.now() and Dates.now(UTC) give the same answer
if the TZ environment variable is set appropriately, but of course
we can't guarantee that these calls run at the same time. Rather
than setting an arbitrary limit of 1 second, just run `Dates.now`
again. Our semantics guarantee ordering of these calls (in the
absence of leap days/seconds at least), so the test is more robust.

[1] https://buildkite.com/julialang/julia-master/builds/22064#0186ff11-f07e-4ba4-9b54-21bdf738d35e
@vtjnash vtjnash added the status:merge me PR is reviewed. Merge when all tests are passing label Mar 21, 2023
@vtjnash
Copy link
Sponsor Member

vtjnash commented Mar 21, 2023

Fixes #48272

@giordano giordano linked an issue Mar 21, 2023 that may be closed by this pull request
@Keno Keno removed the status:merge me PR is reviewed. Merge when all tests are passing label Mar 21, 2023
@Keno
Copy link
Member Author

Keno commented Mar 21, 2023

Welp, the test failed on CI.

@Keno
Copy link
Member Author

Keno commented Mar 21, 2023

Ah, the issue is that now() truncates, while now(UTC) rounds. I'm thinking truncation is the correct behavior for these functions, so I'll add an appropriate commit.

The operating system clock provides the current time in microseconds,
but `DateTime` has milisecond precision. The question is what rounding
to apply. `now` was using truncation, while `now(UTC)` was using rounding.
I think truncation is probably the better default, since you're often
interested in whether a particular `DateTime` has passed, so change `now(UTC)`
to trucate as well.
@Keno
Copy link
Member Author

Keno commented Mar 21, 2023

Alright, added a commit to truncate now(UTC) rather than rounding and deleted the comment I made where I was temporarily confused.

@Keno
Copy link
Member Author

Keno commented Mar 22, 2023

@quinnj Does the rounding change look resaonable to you?

@Keno
Copy link
Member Author

Keno commented Mar 23, 2023

I'm just gonna say this is fine and merge this, but @quinnj let me know if you have concerns.

@Keno Keno merged commit e33b31b into master Mar 23, 2023
@Keno Keno deleted the kf/dateconversrobust branch March 23, 2023 18:52
Xnartharax pushed a commit to Xnartharax/julia that referenced this pull request Apr 19, 2023
* Improve robustness in Dates/conversions test

In [1], this test was observed to fail, with a 1 second pause between
the two Dates.now calls. In general, particularly on high-load CI
systems, we cannot make assumptions that calls will complete within
any particular amount of time. Instead, we should be asserting
properties that should be universally true. This test wants to
assert that Dates.now() and Dates.now(UTC) give the same answer
if the TZ environment variable is set appropriately, but of course
we can't guarantee that these calls run at the same time. Rather
than setting an arbitrary limit of 1 second, just run `Dates.now`
again. Our semantics guarantee ordering of these calls (in the
absence of leap days/seconds at least), so the test is more robust.

[1] https://buildkite.com/julialang/julia-master/builds/22064#0186ff11-f07e-4ba4-9b54-21bdf738d35e

* now: Consistently truncate DateTime rather than rounding

The operating system clock provides the current time in microseconds,
but `DateTime` has milisecond precision. The question is what rounding
to apply. `now` was using truncation, while `now(UTC)` was using rounding.
I think truncation is probably the better default, since you're often
interested in whether a particular `DateTime` has passed, so change `now(UTC)`
to trucate as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dates/conversions test bug
3 participants