Re:Microsoft Exchange stops passing mail due to bug on 1/1/22
by Hamuko on Saturday January 01, 2022 @09:38AM
(#29758579)
Our unit tests break twice a year, starting a couple of days before DST change. I'm sure it could be solved, but since the DST change happens on Sunday and the CI builds fail on Friday, no one has really bothered.
[ Parent
| on HN ]
Re:Microsoft Exchange stops passing mail due to bug on 1/1/22
by Dunedan on Saturday January 01, 2022 @01:11PM
(#29760963)
So I guess your units tests run with the current date and don't test behavior with different dates. That's something which has the potential to hide quite a few date related bugs until it's too late.
What I like to do to avoid this situation is to use property-based testing to test that the code works for all dates in the desired time span. For Python I use hypothesis [1] in combination with freezegun [2] for that. Here is an example of how that could look like:
from datetime import datetime, timezone as tz
from freezegun import freeze_time
from hypothesis import given, strategies as st
def business_logic():
# TODO: Refactor before 2038!
if datetime.now(tz=tz.utc) > datetime(2038, 1, 19, 3, 14, 7, tzinfo=tz.utc):
raise Exception("This code is not working after UNIX time overflow")
...
@given(dt=st.datetimes(max_value=datetime(9999, 12, 31, 23, 59, 59), timezones=st.just(tz.utc)))
def test_business_logic(dt):
with freeze_time(dt):
business_logic()
test_business_logic()
[1]: https://hypothesis.readthedocs.io/en/latest/
Re:Microsoft Exchange stops passing mail due to bug on 1/1/22
by Hamuko on Saturday January 01, 2022 @02:39PM
(#29761859)
It's just that the unit tests are built on the assumption that if you go forwards 24/48/72 hours, the time will be the same but N day(s) ahead. And that breaks down when you shift time zones.
>don't test behavior with different dates
It basically tests with different dates every time it's run.
Re:Microsoft Exchange stops passing mail due to bug on 1/1/22
by denton-scratch on Saturday January 01, 2022 @01:49PM
(#29761314)
> the CI builds fail on Friday
That seems different from what I understand by "continuous integration".
Re:Microsoft Exchange stops passing mail due to bug on 1/1/22
by patmorgan23 on Saturday January 01, 2022 @06:39PM
(#29764067)
It's just an unintentional read-only Friday