Repository navigation
Ignore redundant idle notifications in IdlingResourceRegistry. - #2536
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
`IdlingResource.isIdleNow()` permits implementations to invoke `ResourceCallback.onTransitionToIdle()` when reporting that they are idle. When `IdlingResourceRegistry` registers an already-idle resource or polls `allResourcesAreIdle()` on the registry looper, resources that unconditionally invoke `onTransitionToIdle()` inside `isIdleNow()` leave a redundant `DYNAMIC_RESOURCE_HAS_IDLED` message queued on the main `Looper`. That queued message prevents callers that inspect the main `Looper` queue after polling `allResourcesAreIdle()` from observing an empty queue. Skip posting `DYNAMIC_RESOURCE_HAS_IDLED` when `onTransitionToIdle()` is invoked on the registry looper while the resource state is already idle, and clear any pending `DYNAMIC_RESOURCE_HAS_IDLED` messages for a resource when `setIdle(true)` transitions it to idle. PiperOrigin-RevId: 1018660560
agammann
reviewed
Nov 11, 2026
agammann
left a comment
There was a problem hiding this comment.
The two guards address different queue paths: setIdle(true) removes a callback queued during registration, while the looper check avoids enqueueing another one when isIdleNow() is polled after the resource is idle. The new test checks an empty queue after registration, polling, and a direct redundant callback; the existing repeated-transition test still covers real busy-to-idle changes.
This branch has not been deployed
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.
Ignore redundant idle notifications in IdlingResourceRegistry.
IdlingResource.isIdleNow()permits implementations to invokeResourceCallback.onTransitionToIdle()when reporting that they are idle. WhenIdlingResourceRegistryregisters an already-idle resource or pollsallResourcesAreIdle()on the registry looper, resources that unconditionally invokeonTransitionToIdle()insideisIdleNow()leave a redundantDYNAMIC_RESOURCE_HAS_IDLEDmessage queued on the mainLooper. That queued message prevents callers that inspect the mainLooperqueue after pollingallResourcesAreIdle()from observing an empty queue.Skip posting
DYNAMIC_RESOURCE_HAS_IDLEDwhenonTransitionToIdle()is invoked on the registry looper while the resource state is already idle, and clear any pendingDYNAMIC_RESOURCE_HAS_IDLEDmessages for a resource whensetIdle(true)transitions it to idle.