-
Notifications
You must be signed in to change notification settings - Fork 4k
Count in-flight Pusher applies as applied when detecting update gaps #99774
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
Merged
mountiny
merged 17 commits into
Expensify:main
from
callstack-internal:2882-pusher-gap-detection
Sep 9, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a77a3ce
Count in-flight Pusher applies as applied when detecting update gaps
adhorodyski 1bee93a
Release a held Pusher apply after every test so a failure stays local
adhorodyski 61e6e1c
Merge branch 'Expensify:main' into 2882-pusher-gap-detection
adhorodyski 0d70c51
Merge branch 'Expensify:main' into 2882-pusher-gap-detection
adhorodyski 9a0e675
Say why the pending-apply marker is cleared for every failed apply
adhorodyski f1f9591
Merge branch 'Expensify:main' into 2882-pusher-gap-detection
adhorodyski abe7602
Stop two gap-detection tests depending on where they sit in the file
adhorodyski 77bd7e1
Name the reason for resetModules instead of commenting it
adhorodyski 1774103
Merge branch 'Expensify:main' into 2882-pusher-gap-detection
adhorodyski 20934ef
Merge branch 'Expensify:main' into 2882-pusher-gap-detection
adhorodyski 4bef1ec
Merge branch 'Expensify:main' into 2882-pusher-gap-detection
adhorodyski 2e59104
Read the pending apply marker only for Pusher gap checks
adhorodyski a46cca9
Pin the pusherEventsPromise coupling in its own test
adhorodyski a3195c6
Merge remote-tracking branch 'origin/2882-pusher-gap-detection' into …
adhorodyski 554bec0
Merge branch 'Expensify:main' into 2882-pusher-gap-detection
adhorodyski 275c1a5
Name the Pusher gap-check gate and restore the deferred-write note
adhorodyski 9c0c59c
rename variables to address the review round
adhorodyski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import PusherUtils from '@libs/PusherUtils'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import {apply, doesClientNeedToBeUpdated} from '@src/libs/actions/OnyxUpdates'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {OnyxUpdatesFromServer} from '@src/types/onyx'; | ||
|
|
||
| import type {OnyxKey} from 'react-native-onyx'; | ||
|
|
||
| import Onyx from 'react-native-onyx'; | ||
|
|
||
| import getOnyxValue from '../utils/getOnyxValue'; | ||
| import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
|
|
||
| const pusherUpdate = (previousUpdateID: number, lastUpdateID: number): OnyxUpdatesFromServer<OnyxKey> => ({ | ||
| type: CONST.ONYX_UPDATE_TYPES.PUSHER, | ||
| previousUpdateID, | ||
| lastUpdateID, | ||
| updates: [{eventType: 'onyxApiUpdate', data: []}], | ||
| }); | ||
|
|
||
| // A rejected Pusher apply leaves the module-scoped pusherEventsPromise rejected for the rest of the module's life, | ||
| // so this lives in its own file rather than poisoning the chain for the other tests. | ||
| describe('OnyxUpdates, when a Pusher apply fails', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({ | ||
| keys: ONYXKEYS, | ||
| }); | ||
| }); | ||
|
|
||
| beforeEach(() => Onyx.clear().then(waitForBatchedUpdates)); | ||
|
|
||
| it('relies on pusherEventsPromise staying rejected to stop a follower whose gap check the failed update had suppressed', async () => { | ||
| // Given the client is caught up to update 10 and update 20 from Pusher is held mid-apply | ||
| await Onyx.merge(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT, 10); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| let failHeldApply: (error: Error) => void = () => {}; | ||
| let handlerCallCount = 0; | ||
| const handlerSpy = jest.spyOn(PusherUtils, 'triggerMultiEventHandler').mockImplementation(() => { | ||
| handlerCallCount += 1; | ||
| if (handlerCallCount > 1) { | ||
| return Promise.resolve(); | ||
| } | ||
| return new Promise<void>((resolve, reject) => { | ||
| failHeldApply = reject; | ||
| }); | ||
| }); | ||
| const heldApply = apply(pusherUpdate(10, 20)); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| // When update 30 arrives chained on it, so the pending marker tells it there is no gap | ||
| expect(doesClientNeedToBeUpdated({previousUpdateID: 20, updateType: CONST.ONYX_UPDATE_TYPES.PUSHER})).toBe(false); | ||
| const followerApply = apply(pusherUpdate(20, 30)); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| // And update 20 then fails to apply | ||
| failHeldApply(new Error('storage write failed')); | ||
| await expect(heldApply).rejects.toThrow('storage write failed'); | ||
| await expect(followerApply).rejects.toThrow('storage write failed'); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| // Then update 30 is never written either. Nothing checks that update IDs are contiguous before advancing the | ||
| // watermark, so were it written the watermark would move to 30 and updates 11 to 20 would be lost with no gap | ||
| // left to trigger recovery. Serializing on pusherEventsPromise is the only thing preventing that. | ||
| expect(handlerCallCount).toBe(1); | ||
| expect(await getOnyxValue(ONYXKEYS.ONYX_UPDATES_LAST_UPDATE_ID_APPLIED_TO_CLIENT)).toBe(10); | ||
|
|
||
| // And both updates are back in the gap, so recovery can refetch them | ||
| expect(doesClientNeedToBeUpdated({previousUpdateID: 20, updateType: CONST.ONYX_UPDATE_TYPES.PUSHER})).toBe(true); | ||
| expect(doesClientNeedToBeUpdated({previousUpdateID: 30, updateType: CONST.ONYX_UPDATE_TYPES.PUSHER})).toBe(true); | ||
|
|
||
| handlerSpy.mockRestore(); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.