-
-
Notifications
You must be signed in to change notification settings - Fork 29k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix flaky light group test #12843
Fix flaky light group test #12843
Conversation
Oh noes :/ I've tried your patch locally, but the tests still seems to be flaky. I went ahead and added the Now comes the confusing part: If I add a
Using the " Edit:
|
We should not make changes to the code to make it slower to fight a flaky test |
@balloob All with you on that, but I think the error doesn't lie in the
|
oh, good point. In that case we should collect all existing states when getting added to HASS and process them. |
So I guess I'll close this PR then as it is not the right solution. |
Exactly, but which one of these do you prefer? As far as I see they pretty much have the same result, but there might be some differences between the two. 1.# in async_setup_platform()
async_add_devices([GroupLight(config.get(CONF_NAME),
config[CONF_ENTITIES])], True) # True <------- 2.async def async_added_to_hass(self) -> None:
"""Register callbacks."""
@callback
def async_state_changed_listener(entity_id: str, old_state: State,
new_state: State):
"""Handle child updates."""
self.async_schedule_update_ha_state(True)
self._async_unsub_state_changed = async_track_state_change(
self.hass, self._entity_ids, async_state_changed_listener)
self.async_schedule_update_ha_state(True) # <----- |
The first one. |
Description:
https://travis-ci.org/home-assistant/home-assistant/jobs/348247842#L994
#12229 (comment)
The new
light.group
test introduced a flaky test. It's caused by having an async state change listener that is a callback. Callbacks are not tracked by the core when tracking jobs and thus will not be waited for when callinghass.async_block_till_done()
. They can usually be flushed out by doing asleep(0)
whichasync_block_till_done
does, but if a callback calls another callback, that won't work.So for this case, let's switch to calling
async_block_till_done
twice.Checklist:
If the code does not interact with devices:
tox
run successfully. Your PR cannot be merged unless tests pass