Skip to content

Test the stated span with a key that covers now - #8

Merged
jwrosewell merged 1 commit into
mainfrom
fix/recent-minute-test-date
Oct 6, 2026
Merged

jwrosewell merged 1 commit into
mainfrom
fix/recent-minute-test-date

Conversation

@jwrosewell

@jwrosewell jwrosewell commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

test_a_recent_minute_is_served_where_the_creator_stated_the_span in tests/test_public_key_fetch.py fails on main on any day from 21 September 2026. Run on main at 80495f4 on 5 October 2026, the CI command gives the result below.

python -m unittest discover
...
AssertionError: 1 != 3 : the current key was served for every recent minute from one answer
Ran 177 tests
FAILED (failures=1)

The last CI run on main was on 7 September 2026, before the date mattered, so main still shows a green tick.

Cause

The test reads the clock and asks for the key at three minutes near now. The stand in end point the test used fixes the moment of a request at 14 September 2026 and reads any later date as that moment (REQUEST_MOMENT in tests/key_end_point.py). Up to 20 September the answer was the key in force now, with a span that held all three minutes, so one request served them. From 21 September the answer is the key for the week of 14 September, whose span holds none of the minutes asked about, so each minute is fetched and the test counts three requests.

Change

The creator in this test now states one key for the day either side of now. The test defines a small end point that answers every request with that one key, built with endpoints.public_key_answer, in place of the fixture schedule. The three requests and the assertion are unchanged. The skip that depended on the fixture schedule is gone, so the test also keeps checking after 30 November 2026, when the last key in the fixture starts and the old test would have skipped.

The old test also depended on the time of day. Replayed with the clock set to 00:05 on 14 September 2026, the old steps counted two requests, because in the first ten minutes of a key's week the minute ten minutes back belongs to the week before. The new steps counted one request at every moment tried.

The .NET library's test of the same behaviour is already written this way, as ARecentMinuteIsServedWhereTheCreatorStatedTheSpan in Owid.Client.Test/PublicKeyFetchTests.cs, and the Rust library has the same change in SWAN-community/owid-rust#13.

Only tests/test_public_key_fetch.py changes. No library code, helper or fixture changes.

Verification

Run on Windows on 5 October 2026 with the two commands of the CI workflow.

  • pip install . succeeds.
  • python -m unittest discover runs 177 tests and passes on Python 3.14.7 and on Python 3.9.1, where main gives one failure. Python 3.12, which the CI uses, was not available locally.
  • With the condition in _held_for in owid/public_key_fetch.py changed from key.explicit or not recent to not recent, the changed test fails with 1 != 3, so the test still depends on the behaviour its name describes. That change was then put back.

Outstanding

The same test in the Go, Java, PHP, Python and Rust libraries has the same cause, and failed in each when the one test was run on each main on 5 October 2026. The other four are changed in SWAN-community/owid-rust#13, SWAN-community/owid-go#19, SWAN-community/owid-java#10 and SWAN-community/owid-php#7.

The test that checks a recent minute is served from a span the creator
stated read the clock, whilst the stand in end point it used answers for
no moment after 14 September 2026. From 21 September 2026 the end point
therefore answered with a key whose span did not hold the minutes asked
about, each one was fetched, and the test failed with three requests
where it expects one.

The creator in the test now states one key for the day either side of
now, as the .NET test does, so the test no longer depends on the dates in
the fixture schedule and keeps checking after the last key in the fixture
has started.
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.

1 participant