Skip to content

Follow Up: add operationRepoLoadedListener and implement it to RecoverFromDroppe…#2075

Merged
jinliu9508 merged 2 commits intomainfrom
add-operationRepo-onLoaded-Listener
May 6, 2024
Merged

Follow Up: add operationRepoLoadedListener and implement it to RecoverFromDroppe…#2075
jinliu9508 merged 2 commits intomainfrom
add-operationRepo-onLoaded-Listener

Conversation

@jinliu9508
Copy link
Copy Markdown
Contributor

@jinliu9508 jinliu9508 commented May 3, 2024

Description

One Line Summary

This is a followup PR to address a broken change made by this PR #2068

Details

Motivation

The PR mentioned above has made the initialization of OperationRepo asynchronous that we can no longer assume all saved operations are loaded at start. This PR adds an event listener to RecoverFromDroppedLoginBug so that it listens to the loading completion event and starts the recovery after the loading has completed.

Scope

The recover does no longer begin at start. Instead, it will begin when it receives the event notifier that the loading of OperationRepo has completed.

Testing

Unit testing

I have added two test units to ensure both classes are working properly.

Manual testing

My manual testing step:

  1. enter the example app and turn wifi off
  2. perform a Login
  3. kill and re-enter the app
  4. notice that RecoverFromDroppedLoginBug inserts a LoginUser operation into the operationRepo queue, after the loading is completed

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

Comment on lines +596 to +609

test("IOperationRepoLoadedListener") {
val mocks = Mocks()
val mockIdentityModel = mockk<IdentityModel>()
val mockIdentityModelStore = mockk<IdentityModelStore>()
val recovery = RecoverFromDroppedLoginBug(mocks.operationRepo, mockIdentityModelStore, mocks.configModelStore)

mocks.operationRepo.start()
recovery.start()

verify {
mocks.operationRepo.subscribe(recovery)
}
}
Copy link
Copy Markdown
Member

@jkasten2 jkasten2 May 3, 2024

Choose a reason for hiding this comment

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

This is testing RecoverFromDroppedLoginBug instead of OperationRepo, as the only thing we are verifying is that operationRepo.subscribe was called. This is a fine test, but such a test would belong in RecoverFromDroppedLoginBugTest.kt.

If we want to test the new OperationRepo feature, we should test that it actually fired the event instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point! I have fixed that and add one test unit in each class to ensure the event listener works correctly.

@jinliu9508 jinliu9508 requested a review from jkasten2 May 3, 2024 21:41
@jinliu9508 jinliu9508 changed the title WIP: Follow Up: add operationRepoLoadedListener and implement it to RecoverFromDroppe… Follow Up: add operationRepoLoadedListener and implement it to RecoverFromDroppe… May 3, 2024
@jinliu9508 jinliu9508 merged commit 702d13c into main May 6, 2024
@jinliu9508 jinliu9508 deleted the add-operationRepo-onLoaded-Listener branch May 6, 2024 17:05
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