Fix OpenRGB tests failing CI#155095
Conversation
|
Hey there @felipecrs, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes flaky OpenRGB test failures in CI by replacing multiple sequential calls to hass.async_block_till_done() with a single call that waits for background tasks to complete. The issue was caused by unpredictable timing when repeatedly calling async_block_till_done() without waiting for background tasks, leading to race conditions in tests that verify state updates after time intervals.
Key Changes
- Replaced repeated
async_block_till_done()calls withasync_block_till_done(wait_background_tasks=True) - Applied fix consistently across 7 test functions that were experiencing timing issues
|
Thanks a lot for fixing it! I didn't realize it was causing trouble. FYI there are multiple other integrations that do the same, like Tasmota. May be worth refactoring them too, even though they are not causing test failures. Would prevent other people from using them as reference, like I did. |
Replace multiple consecutive async_block_till_done() calls with single async_block_till_done(wait_background_tasks=True) calls after async_fire_time_changed() in test files. This pattern is more reliable and predictable than calling async_block_till_done() multiple times, which doesn't guarantee proper handling of all async operations and can lead to flaky tests. Affected integrations: - knx: 2 instances in test_init.py - nest: 1 instance in test_media_source.py - openrgb: 3 instances in test_init.py (including one with 3 consecutive calls) - playstation_network: 1 instance in test_image.py - rflink: 2 instances in test_binary_sensor.py - sun: 1 instance in test_init.py - template: 4 instances (1 in test_sensor.py, 3 in test_trigger.py) Total: 14 instances fixed across 7 integrations. Follows the same fix pattern from PR #155095 which addressed similar issues in the openrgb light tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Proposed change
I noticed the following test failing CI:
https://github.com/home-assistant/core/actions/runs/18771740545/job/53557992992?pr=155073#step:11:249
Looking at the implementation it calls
hass.async_block_till_done()multiple time to wait for an update, this doesn't make sense since it is not predictable and reaching a situation like this a good marker for something incorrect in the test.core/tests/components/openrgb/test_light.py
Lines 377 to 380 in 3c098db
core/tests/components/openrgb/test_light.py
Lines 802 to 807 in 3c098db
I produced the problem and by waiting for background tasks it fixes the test failure.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: