alan-turing-institute / data-safe-haven

https://data-safe-haven.readthedocs.io
BSD 3-Clause "New" or "Revised" License
50 stars 14 forks source link

Tests for next_occurrence break at certain times of day #1895

Closed jemrobinson closed 1 month ago

jemrobinson commented 1 month ago

:white_check_mark: Checklist

:computer: System information

:package: Packages

List of packages ```none acme==2.6.0 annotated-types==0.6.0 appdirs==1.4.4 Arpeggio==2.0.2 attrs==23.2.0 azure-common==1.1.28 azure-core==1.30.1 azure-identity==1.16.0 azure-keyvault-certificates==4.8.0 azure-keyvault-keys==4.9.0 azure-keyvault-secrets==4.8.0 azure-mgmt-automation==1.0.0 azure-mgmt-compute==30.6.0 azure-mgmt-containerinstance==10.1.0 azure-mgmt-core==1.4.0 azure-mgmt-dns==8.1.0 azure-mgmt-keyvault==10.3.0 azure-mgmt-msi==7.0.0 azure-mgmt-network==25.3.0 azure-mgmt-rdbms==10.1.0 azure-mgmt-resource==23.0.1 azure-mgmt-storage==21.1.0 azure-storage-blob==12.19.1 azure-storage-file-datalake==12.14.0 azure-storage-file-share==12.15.0 certifi==2024.2.2 cffi==1.16.0 charset-normalizer==3.3.2 chevron==0.14.0 click==8.1.7 cryptography==42.0.6 -e git+ssh://git@github.com/jemrobinson/data-safe-haven.git@cb3d09511884bff82ab33b39e18b1db74dad7959#egg=data_safe_haven dill==0.3.8 dnspython==2.4.2 fqdn==1.5.1 grpcio==1.60.1 idna==3.7 iniconfig==2.0.0 isodate==0.6.1 josepy==1.14.0 markdown-it-py==3.0.0 mdurl==0.1.2 msal==1.28.0 msal-extensions==1.1.0 msrest==0.7.1 oauthlib==3.2.2 packaging==24.0 parver==0.5 pluggy==1.5.0 portalocker==2.8.2 protobuf==4.25.3 psycopg==3.1.18 pulumi==3.115.0 pulumi_azure_native==2.39.0 pulumi_random==4.16.1 pycparser==2.22 pydantic==2.7.1 pydantic_core==2.18.2 Pygments==2.18.0 PyJWT==2.8.0 pyOpenSSL==24.1.0 pyRFC3339==1.1 pytest==8.2.0 pytest-asyncio==0.23.6 pytz==2023.4 PyYAML==6.0.1 requests==2.31.0 requests-oauthlib==2.0.0 rich==13.7.1 semver==2.13.0 setuptools==69.5.1 shellingham==1.5.4 simple-acme-dns==3.0.0 six==1.16.0 typer==0.12.3 typing_extensions==4.11.0 urllib3==2.2.1 validators==0.22.0 websocket-client==1.8.0 ```

:no_entry_sign: Describe the problem

At certain times of day next_occurrence can choose a datetime more than 1 day in the future, causing the tests to break.

:deciduous_tree: Log messages

Relevant log messages ```none ___________________ test_next_occurrence_is_within_next_day ____________________ def test_next_occurrence_is_within_next_day(): next_time = next_occurrence(5, 13, "Australia/Perth") dt_next_time = datetime.datetime.fromisoformat(next_time) dt_utc_now = datetime.datetime.now(datetime.UTC) assert dt_next_time > dt_utc_now > assert dt_next_time < dt_utc_now + datetime.timedelta(days=1) E AssertionError: assert datetime.datetime(2024, 5, 17, 21, 13, tzinfo=datetime.timezone.utc) < (datetime.datetime(2024, 5, 16, 16, 52, 28, 540053, tzinfo=datetime.timezone.utc) + datetime.timedelta(days=1)) E + where datetime.timedelta(days=1) = (days=1) E + where = datetime.timedelta tests/functions/test_strings.py:16: AssertionError ```

:recycle: To reproduce

Run hatch run test:test at around 16:15 UTC.