Repository navigation
Fix the test that fails for one hour a day, every night the journal flush runs - #5013
Merged
Merged
Conversation
…t the host's test_energydataservice built its rate fixture from datetime.now() - the machine's clock - while reading the timezone offset two lines later from my_predbat.midnight_utc, which is local midnight in Predbat's configured timezone. Between 23:00 and 00:00 UTC under BST those land on different dates, so the published rates are a day out from the day the code is modelling and rates[1440] does not exist: KeyError: 1440. This is not intermittent. The nightly journal flush runs at local midnight, which during BST is 23:0x UTC, so it lands in the failing hour every night - PR #5011 is a docs-only change that failed CI for exactly this reason, at 23:12 UTC. Same trap and same fix as PR #4998 for the multi-car IOG tests, and the trap already has a bullet in the debug journal ("Build test dates from Predbat's clock, not the machine's"). Verified by running the suite with TZ=Pacific/Pitcairn, which puts the host a calendar day behind Europe/London: energydataservice reproduces the KeyError before the change and passes after, as does the full quick suite (82.98s, 4 slow tests skipped). It also still passes on an unshifted clock. The suite aborts on the first uncaught exception, so this was masking anything later in the run; with it fixed, nothing else in the quick suite fails in that window. Nineteen other test files call datetime.now(), none of them currently affected, but the pattern is latent - a scheduled CI run in a shifted timezone would catch the next one before a maintainer does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped to a test fixture, aligns all date/offset inputs to the same clock, and I found no functional or maintainability issues in the updated code.
Pull request overview
This PR fixes a deterministic timezone/date mismatch in the test_energydataservice fixture that caused CI failures for one hour per day during BST, by aligning the fixture’s date source with Predbat’s own configured clock (my_predbat.midnight_utc).
Changes:
- Build
today/tomorrowfixture dates frommy_predbat.midnight_utcinstead ofdatetime.now()to avoid host-vs-harness day disagreement. - Add an in-test comment explaining the failure window and why anchoring to Predbat’s clock resolves it.
File summaries
| File | Description |
|---|---|
| apps/predbat/tests/test_energydataservice.py | Anchors test fixture dates to Predbat’s configured local-midnight clock to eliminate the 23:00–00:00 UTC BST failure window. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
test_energydataservicefails for one hour a day, and the nightly journal flush is scheduled inside that hour.The bug
The fixture dates come from the host, the offset from Predbat (Europe/London in the harness). When those disagree on the date, the published rates are a day out from the day the code is modelling and
rates[1440]doesn't exist —KeyError: 1440.On a UTC runner during BST they disagree between 23:00 and 00:00 UTC.
Why it matters now
This isn't intermittent flakiness. The nightly
/journal-updateflush fires at local midnight, which during BST is 23:0x UTC — so it lands in the failing hour every night. #5011 is a docs-only change (one markdown file) that failed CI at 23:12 UTC for exactly this reason. Until BST ends in late October, every nightly journal PR fails the same way.The fix
Anchor the fixture to
my_predbat.midnight_utc— the same clock the next line already reads. Identical trap and identical fix to #4998 for the multi-car IOG tests last week, and the trap already has a bullet in the debug journal ("Build test dates from Predbat's clock, not the machine's").Verification
Reproduced with
TZ=Pacific/Pitcairn, which puts the host a calendar day behind Europe/London:--test energydataservice, shifted TZKeyError: 1440--test energydataservice, normal TZ--quick, shifted TZThe suite aborts on the first uncaught exception, so this was masking anything later in the run. With it fixed, nothing else in the quick suite fails in that window.
Worth considering separately
Nineteen other test files call
datetime.now(). None is currently affected — I checked by running the whole suite in the window — but the pattern is latent, and this is the second instance in a week. A scheduled CI run in a shifted timezone would catch the next one before a maintainer does. I haven't added one here since it's a workflow change with its own cost.🤖 Generated with Claude Code