-
Notifications
You must be signed in to change notification settings - Fork 15
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
Fix next_occurrence function #1893
Fix next_occurrence function #1893
Conversation
…oid it choosing a datetime more than 1 day in the future
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
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 don't like this.
I've lost track of what next_occurrence
is trying to do and adding minutes in odd places feels like fudge factors.
utc_now = datetime.datetime.now(pytz.utc) + datetime.timedelta(minutes=1)
This isn't true, for example, that is now plus one minute.
If the problem is the test isn't true sometimes, it would be better to make the tests deterministic by not using datetime.now()
but a set of known times instead.
Previously, we took local-time-in-UTC + 1 day which is always in the future (over the lifetime of a deploy operation). However, this can break the test which assumes that the output of Possible solutions are:
I'm happy to switch to solution (1) if you prefer. |
Hmm, some thoughts that might help,
|
Just because that's the intention of the function (to generate the UTC timestamp corresponding to the next time it is e.g. 3am in Perth)
No, it doesn't have to be, but some of these schedulers won't start until the time occurs, so it would bad bad if this was e.g. 10 days in the future.
Potentially, but I think there should be a maximum window on how far in the future it could be (see above)
Happy to remove this fudge (esp. given your comments above)
I think it only needs to be one function - the important thing is to come up with a UTC value that represents when your thing will happen in the future. |
126d2da
to
6861cc1
Compare
6861cc1
to
1eb9293
Compare
Looks like you can't mock builtin methods. I'll have a go with |
348a397
to
3a03e33
Compare
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.
Added some extra tests with @parametrize
and a test for DST.
✅ Checklist
Enable foobar integration
rather than515 foobar
).develop
.🚦 Depends on
n/a
Ensure that next_occurrence only adds one day when necessary, to avoid it choosing a datetime more than 1 day in the future
🌂 Related issues
Closes #1895
🔬 Tests
Check CI