Skip to content

test: collect #746 bus events on the event loop to keep their order - #784

Merged
GreenGrassBlueOcean merged 1 commit into
v2-phase1-architecturefrom
fix/flaky-test-746-cen-order
Oct 23, 2026
Merged

GreenGrassBlueOcean merged 1 commit into
v2-phase1-architecturefrom
fix/flaky-test-746-cen-order

Conversation

@GreenGrassBlueOcean

Copy link
Copy Markdown
Contributor

Problem

test_issue_746_switch_04_wall_and_ha_toggling_and_scenario_6_events failed once on the HA Compatibility (beta) job of #781 (run 39998271332):

assert 'pushbutton_short_release' == 'pushbutton_short_press'   (tests/test_issue_746_mh200n_trace.py:183)

Both CEN events were fired (the count assertion passed) but landed in the wrong order. That PR only changed comments. The same test passed on its previous run, on v2-phase1-architecture seven minutes earlier, and on the stable and dev jobs of the same run.

Cause

The test registered cen_events.append (and the scene / general-light lists) as plain event-bus listeners. Home Assistant runs a listener that is neither a coroutine function nor marked @callback as an executor job, so two events fired back to back can be appended in either order.

Fix

Register the listeners through a small @callback helper. They then run on the event loop, in firing order.

Verification

  • The test passes 25/25 runs locally with the change.
  • I could not reproduce the flake locally. The unchanged test also passed 25/25, so the executor ordering is the explanation from how Home Assistant dispatches listeners, not something I observed failing. A timing-dependent failure like this one only shows up under CI load.
  • Two other tests register list.append listeners (test_access_policy.py, test_issue_368_resync.py). They wait for a single event, so order cannot matter there, and I left them alone.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@GreenGrassBlueOcean
GreenGrassBlueOcean merged commit 45b7d13 into v2-phase1-architecture Oct 23, 2026
17 checks passed
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.

2 participants