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

[Improvement] Prevent OperationRepo's 5 second wait from being skipped, and continuously pulling when empty #2033

Merged
merged 5 commits into from
Mar 28, 2024

Commits on Mar 20, 2024

  1. create test to prove OperationRepo isn't sleeping

    Create test to confirm that OperationRepo.processQueueForever keeps poll
    when it should suspend the thread while waiting for the next operation.
    
    My theory is this polling every 5 seconds means the app process may
    never fully sleep, which contributes to battery drain.
    
    We moved code to a new getNextOps() function simply to make it testable,
    no logic changes in this commit.
    jkasten2 committed Mar 20, 2024
    Configuration menu
    Copy the full SHA
    a83ab97 View commit details
    Browse the repository at this point in the history
  2. Deduplicated mock code across OperationRepoTests

    Created a new private Mocks class to encapsulate creating the depended
    mocks into a one liner each test can use. Some tests override the
    provided mock behavior by calling every {} again.
    jkasten2 committed Mar 20, 2024
    Configuration menu
    Copy the full SHA
    ca02343 View commit details
    Browse the repository at this point in the history
  3. Fix extra OperationRepo.processQueueForever pulls

    Refactored OperationRepo.processQueueForever to prevent it from
    continuously pulling when the queue is empty. My theory is this polling
    every 5 seconds means the app process may never fully sleep, which
    contributes to battery drain.
    
    This commit makes the
    "ensure processQueueForever suspends when queue is empty" pass.
    jkasten2 committed Mar 20, 2024
    Configuration menu
    Copy the full SHA
    1c2fd11 View commit details
    Browse the repository at this point in the history

Commits on Mar 28, 2024

  1. fix multiple enqueues skipping waitForWake

    We renamed waitForWake to waitForNewOperationAndExecutionInterval to
    describe that it is doing two things.
    
    Fixed the logic where enqueuing two or more operations would skip our
    executionInterval logic. Added test coverage for this logic, as well
    as a 2nd test to ensure flush can still skip waiting for it.
    
    Lastly cleaned up the force state in the main processQueueForever loop,
    we were able to fully encapsulate it into
    waitForNewOperationAndExecutionInterval. The other part of the logic is
    once we start processing the queue we want to do so until it's empty
    again, which ops != null is the only checked needed in
    processQueueForever to cover that.
    jkasten2 committed Mar 28, 2024
    Configuration menu
    Copy the full SHA
    bf2cfda View commit details
    Browse the repository at this point in the history
  2. Improve Waiter to not block when calling wake

    We don't want to do any waiting when we call wake, so use trySend
    instead. Also added result checking, to ensure we throw instead of
    silently handling the error so we know if there is an issue at any time.
    jkasten2 committed Mar 28, 2024
    Configuration menu
    Copy the full SHA
    fd60e70 View commit details
    Browse the repository at this point in the history