Skip to content
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

SyncAdapterServices: Use a coroutine scope to cancel waiting on framework request #977

Merged
merged 2 commits into from
Aug 14, 2024

Conversation

rfc2822
Copy link
Member

@rfc2822 rfc2822 commented Aug 13, 2024

Purpose

Currently, the SyncAdapterServices (handles syncs initiated by the Android sync framework) runs a sync job and waits for the result, but does not abort waiting when the sync framework requests cancellation.

The finished variable which was made for this is not evaluated.

Note that "cancellation" in this context shall never cancel the actual sync worker, but only the sync framework job (that waits for the worker to finish).

Short description

Now we use a coroutine scope instead.

  • When the sync completes in time, collect is cancelled, waitJob finishes and waitJob.join() just returns.
  • When the framework sync is cancelled by the framework (onSyncCanceled), waitScope is cancelled, thus waitJob is cancelled, and waitJob.join() just returns.
  • When the framework sync is cancelled by timeout, withTimeout cancels and a log message is printed.

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

@rfc2822 rfc2822 linked an issue Aug 13, 2024 that may be closed by this pull request
@rfc2822 rfc2822 added the bug Something isn't working label Aug 13, 2024
@rfc2822 rfc2822 self-assigned this Aug 13, 2024
@rfc2822 rfc2822 force-pushed the 975-syncadapterservice-doesnt-cancel-on-request branch from c417e91 to 5d9f447 Compare August 13, 2024 09:36
@rfc2822 rfc2822 requested a review from sunkup August 13, 2024 10:58
@rfc2822 rfc2822 marked this pull request as ready for review August 13, 2024 10:58
Copy link
Member

@sunkup sunkup left a comment

Choose a reason for hiding this comment

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

Looks really good. Seems to work fine as well. I wonder a bit though: Should the tests not contain some assert or verify calls? Or are they purely meant to capture the implementation state, such that when it changes a test will fail?

@rfc2822
Copy link
Member Author

rfc2822 commented Aug 14, 2024

Looks really good. Seems to work fine as well. I wonder a bit though: Should the tests not contain some assert or verify calls? Or are they purely meant to capture the implementation state, such that when it changes a test will fail?

The key is the Timeout rule. If something goes wrong in the tests, they will for instance wait 60 seconds to unblock the wait process, but until then the timeout rule has triggered and marked the test as failed.

@rfc2822 rfc2822 merged commit 70f6f26 into main-ose Aug 14, 2024
10 checks passed
@rfc2822 rfc2822 deleted the 975-syncadapterservice-doesnt-cancel-on-request branch August 14, 2024 12:00
@sunkup
Copy link
Member

sunkup commented Aug 14, 2024

Looks really good. Seems to work fine as well. I wonder a bit though: Should the tests not contain some assert or verify calls? Or are they purely meant to capture the implementation state, such that when it changes a test will fail?

The key is the Timeout rule. If something goes wrong in the tests, they will for instance wait 60 seconds to unblock the wait process, but until then the timeout rule has triggered and marked the test as failed.

Smart :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SyncAdapterService doesn't cancel on request
2 participants