Skip to content

Freeze the clock in test_run_automations - #2456

Merged
Flix6x merged 1 commit into
mainfrom
fix/flaky-run-automations-test
Sep 1, 2026
Merged

Freeze the clock in test_run_automations#2456
Flix6x merged 1 commit into
mainfrom
fix/flaky-run-automations-test

Conversation

@Flix6x

@Flix6x Flix6x commented Sep 1, 2026

Copy link
Copy Markdown
Member

Description

test_run_automations invokes flexmeasures jobs run-automations twice and asserts that the second invocation reports nothing due, under the comment "running again within the same minute does not queue jobs twice". That only holds while both invocations land in the same clock minute.

The two automations it sets up recur every minute (* * * * *). The first invocation queues real forecasting jobs, so on a slow runner it can cross a minute boundary — after which both automations are legitimately due again, and the assertion fails:

AssertionError: Automation 1 ('Every minute') queued 1 forecasting job(s) for asset 1.
assert 'No automations due' in "Automation 1 ('Every minute') queued 1 forecasting job(s) ...

Nothing is wrong with the behaviour under test: queueing again in a new minute is exactly what an every-minute automation should do. The test is simply time-dependent, and fails at random.

Observed on Python 3.11 in CI on #2299, but it is not specific to that PR — the assertion is on main, so any PR can hit it.

Change

Froze the clock with the existing freeze_server_now fixture, which the neighbouring test_run_automations_catches_up_once_after_downtime already uses for the same reason. No production code is touched.

How to test

pytest flexmeasures/cli/tests/test_automations.py

No changelog entry, as this changes a test only.


Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or another incompatible license.

Context:
- The test invokes `flexmeasures jobs run-automations` twice and asserts that the second invocation finds nothing due, which only holds while both land in the same clock minute.
- The automations it sets up recur every minute, so once a slow first invocation crosses a minute boundary, they are legitimately due again and the assertion fails. Seen on Python 3.11 in CI.

Change:
- Froze the clock with the existing freeze_server_now fixture, as the neighbouring catch-up test already does, so the test no longer depends on how long its first invocation takes.

Signed-off-by: F.N. Claessen <felix@seita.nl>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 flexmeasures | 🛠️ Build #34336847 | 📁 Comparing c574471 against latest (9ec1271)

  🔍 Preview build  

1 file changed
± api/v3_0.html

@Flix6x
Flix6x merged commit faad360 into main Sep 1, 2026
13 checks passed
@Flix6x
Flix6x deleted the fix/flaky-run-automations-test branch September 1, 2026 17:16
@Flix6x Flix6x added this to the 1.1.0 milestone Sep 1, 2026
@Flix6x Flix6x self-assigned this Sep 1, 2026
@Flix6x Flix6x added bug Something isn't working Continuous Integration labels Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Continuous Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant