Skip to content

Fix OpenRGB tests failing CI#155095

Merged
frenck merged 1 commit intohome-assistant:devfrom
thecode:openrgb-fix-tests
Oct 24, 2025
Merged

Fix OpenRGB tests failing CI#155095
frenck merged 1 commit intohome-assistant:devfrom
thecode:openrgb-fix-tests

Conversation

@thecode
Copy link
Copy Markdown
Member

@thecode thecode commented Oct 24, 2025

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.

freezer.tick(SCAN_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done()
await hass.async_block_till_done()

freezer.tick(SCAN_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done()
await hass.async_block_till_done()
await hass.async_block_till_done()

I produced the problem and by waiting for background tasks it fixes the test failure.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @felipecrs, mind taking a look at this pull request as it has been labeled with an integration (openrgb) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of openrgb can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign openrgb Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with async_block_till_done(wait_background_tasks=True)
  • Applied fix consistently across 7 test functions that were experiencing timing issues

Copy link
Copy Markdown
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @thecode 👍

../Frenck

@frenck frenck merged commit 1d8eaeb into home-assistant:dev Oct 24, 2025
36 checks passed
@thecode thecode deleted the openrgb-fix-tests branch October 24, 2025 14:24
@felipecrs
Copy link
Copy Markdown
Contributor

felipecrs commented Oct 24, 2025

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.

frenck pushed a commit that referenced this pull request Oct 24, 2025
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>
@felipecrs felipecrs mentioned this pull request Oct 24, 2025
21 tasks
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants