Fix flaky test_overflow_queue in history websocket tests#171766
Open
bdraco wants to merge 2 commits into
Open
Conversation
Comparing the full bus listener dict can fail when unrelated components asynchronously add or remove EVENT_STATE_CHANGED listeners during the test; capture listeners before and after via a context manager that excludes state_changed.
Contributor
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to make test_overflow_queue in the History websocket API test suite less flaky by changing how it asserts that event bus listeners are not leaked during the test.
Changes:
- Add an
assert_no_listener_leakcontext manager to snapshot bus listeners before/after a block. - Update
test_overflow_queueto use the new context manager and ignoreEVENT_STATE_CHANGEDlistener changes to reduce unrelated flakiness.
Member
Author
|
need to rethink this |
Add a spy on async_track_state_change_event so the test directly asserts the live stream's unsubscribe callable is invoked when the queue overflows, instead of relying on the (unreliable) shared EVENT_STATE_CHANGED bus listener count.
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.
Proposed change
test_overflow_queuecompared the full bus listener dictionary before and after, which flakes when unrelated components asynchronously add or removeEVENT_STATE_CHANGEDlisteners during the test. Replace the inline assert with a context managerassert_no_listener_leakthat captures listeners before and after and ignoresstate_changed. To still verify the live stream subscription is cleaned up on overflow, spy onasync_track_state_change_eventso the test directly asserts the unsubscribe callable is invoked when the queue overflows.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: