Skip to content

Ignore redundant idle notifications in IdlingResourceRegistry. - #2536

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
piper_1018660560
Open

copybara-service[bot] wants to merge 1 commit into
mainfrom
piper_1018660560

Conversation

@copybara-service

Copy link
Copy Markdown

Ignore redundant idle notifications in IdlingResourceRegistry.

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.

`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 agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants