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

After revert: Defer local updates if there are missing updates and only call GetMissingOnyxMessages once #39683

Conversation

chrispader
Copy link
Contributor

@chrispader chrispader commented Apr 5, 2024

@danieldoglas

Details

This PR applies back the changes from #38997 after the revert in #39668

This PR adds unit and E2E tests covering the OnyxUpdateManager and the new update deferral logic.

Fixed Issues

$ #38748
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Test 1

I created a testing branch that prevents some updates from being applied (therefore GetMissingOnyxUpdates will be triggered) and has some useful logs.

Either test in this branch or on your own. In OnyxUpdateManager do the following:

  1. Delay the call to applyDeferredUpdates with a setTimeout
  2. Prevent some update from being applied
  3. Check that GetMissingOnyxUpdates is triggered
  4. Add some more updates
  5. Check that these updates are added to the deferredUpdates object
  6. Check that no more calls to GetMissingOnyxUpdates are performed
  7. Once the timeout has ended, check that both the missing and deferred updates are applied correctly.

Test 2

  1. Create a chat report with a peer
  2. Create a policy room between both of you
  3. after those rooms are created, and both of you opened them at least once, comment these calls to make sure we're not reloading the data from the backend instead:
    if (isFromDeepLink) {
    // eslint-disable-next-line rulesdir/no-api-side-effects-method
    API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.OPEN_REPORT, parameters, {optimisticData, successData, failureData}).finally(() => {
    Onyx.set(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, false);
    });
    } else {
    // eslint-disable-next-line rulesdir/no-multiple-api-calls
    API.write(
    WRITE_COMMANDS.OPEN_REPORT,
    parameters,
    {optimisticData, successData, failureData},
    {
    getConflictingRequests: (persistedRequests) =>
    // requests conflict only if:
    // 1. they are OpenReport commands
    // 2. they have the same reportID
    // 3. they are not creating a report - all calls to OpenReport that create a report will be unique and have a unique createdReportActionID
    persistedRequests.filter((request) => request.command === WRITE_COMMANDS.OPEN_REPORT && request.data?.reportID === reportID && !request.data?.createdReportActionID),
    },
    );
    }
  4. Now send messages in both chat rooms, alternating between them, and fast, in a way that you can notice if anything is missing (so both start sending some kind of ordered messages, like sequential numbers)
  5. Make sure that none of the messages were lost in those chats.

Offline tests

Not needed.

QA Steps

  • Verify that no errors appear in the JS console
  • Open a chat between two testers
  • Both testers should send consecutive messages at the same time (e.g. 1, 2, 3, 4)
  • No message should be lost between them
  • No more than 1 GetMissingOnyxMessages request should be executed at the same time

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native Screenshot 2024-03-27 at 16 05 13
Android: mWeb Chrome
iOS: Native

Simulator Screenshot - iPhone 15 Pro - 2024-03-27 at 16 10 34

iOS: mWeb Safari
MacOS: Chrome / Safari Screenshot 2024-03-27 at 16 13 55
MacOS: Desktop

Tested deferring logic on web, iOS and Android. mWeb behavior is the same as in web...

…7-@chrispader/prevent-simultaneous-calls-to-GetMissingOnyxMessages"

This reverts commit 3864cdb, reversing
changes made to 42ee04c.
@chrispader chrispader marked this pull request as ready for review April 5, 2024 10:20
@chrispader chrispader requested a review from a team as a code owner April 5, 2024 10:20
@melvin-bot melvin-bot bot removed the request for review from a team April 5, 2024 10:20
Copy link

melvin-bot bot commented Apr 5, 2024

@ Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

This comment has been minimized.

@hungvu193
Copy link
Contributor

hungvu193 commented Apr 5, 2024

Taking a look on test build 👀

@eh2077
Copy link
Contributor

eh2077 commented Apr 5, 2024

@chrispader Could you kindly elaborate how this PR fixes those deploy blocker issues? Thanks!

@hungvu193
Copy link
Contributor

BUG: It always redirects to NotFound page after refreshing a page.

Screen.Recording.2024-04-05.at.17.54.16.mov

@chrispader
Copy link
Contributor Author

@chrispader Could you kindly elaborate how this PR fixes those deploy blocker issues? Thanks!

I cannot say if the change fixes the problem, because this seems to only happen on very-high traffic accounts.

I removed this check for invalid update formats, which unpauses the SequentialQueue which might cause the problem

@danieldoglas
Copy link
Contributor

@hungvu193 I think that's an issue unrelated to this PR, it happens on the PR testing domain

@danieldoglas
Copy link
Contributor

@eh2077 @hungvu193 You'll need to try to simulate a situation with a lot of data going on between you. sending lots of messages on groups both of you are and etc. It's gonna be a tough one to test.

@hungvu193
Copy link
Contributor

@danieldoglas Can you create a slack thread to discuss about testing this PR? It would be better

@chrispader
Copy link
Contributor Author

@danieldoglas Can you create a slack thread to discuss about testing this PR? It would be better

i asked about that here: https://expensify.slack.com/archives/C049HHMV9SM/p1712330961862649?thread_ts=1712264151.436019&cid=C049HHMV9SM

@danieldoglas could you check if there are (other) people that have time and can test this with their accounts?

@hungvu193
Copy link
Contributor

I did few tests over the weekend, I'll test again today with @eh2077

@eh2077
Copy link
Contributor

eh2077 commented Apr 8, 2024

I tried to reproduce this DB issue #39650 but failed to dupe it. I use high traffic accounts.

@eh2077
Copy link
Contributor

eh2077 commented Apr 8, 2024

I tried to reproduce this DB issue #39650 but failed to dupe it. I use high traffic accounts.

@chrispader I managed to reproduce #39650 using two high traffic accounts. It's not stable but I reproduced it by following steps
Preq: Account A on mobile device, Account B on Chrome Web

  1. Send several messages from B to A
  2. Send several messages from A to B
  3. Observed that messages are received normally
  4. Wait a few minutes
  5. Send several messages from A to B
  6. Observed that, from B, the last message is shown in LHN but is not shown in the chat
image

@chrispader
Copy link
Contributor Author

I tried to reproduce this DB issue #39650 but failed to dupe it. I use high traffic accounts.

@chrispader I managed to reproduce #39650 using two high traffic accounts. It's not stable but I reproduced it by following steps Preq: Account A on mobile device, Account B on Chrome Web

  1. Send several messages from B to A
  2. Send several messages from A to B
  3. Observed that messages are received normally
  4. Wait a few minutes
  5. Send several messages from A to B
  6. Observed that, from B, the last message is shown in LHN but is not shown in the chat

you reproduced this with the current branch still?

@chrispader
Copy link
Contributor Author

@hungvu193 i'm also not 100% sure if this isn't somehow caused by my changes in the testing branch by the way i intentionally drop updates and delay them.

@chrispader
Copy link
Contributor Author

chrispader commented Apr 26, 2024

JFYI @danieldoglas @hungvu193 @arosiclair
I'm gonna be OOO from 28/04 until 7. or 8. of May. If we cannot resolve this issue until then, i'm gonna have to hand the PR over to one of my colleagues from Margelo.

@hungvu193
Copy link
Contributor

hungvu193 commented Apr 27, 2024

@hungvu193 i'm also not 100% sure if this isn't somehow caused by my changes in the testing branch by the way i intentionally drop updates and delay them.

Can you try these steps?

  1. Send message from 1 to 9.
  2. Edit messages 9 to 5.
  3. Wait for all updates to be applied.
  4. Add and remove few reactions
  5. Observer the result

I saw the timeout, however I waited for few minutes and still didn't see the updated.
I'll take another test later today

@chrispader
Copy link
Contributor Author

chrispader commented Apr 27, 2024

I saw the timeout, however I waited for few minutes and still didn't see the updated. I'll take another test later today

Ahh i see now what the problem is. It's not the actual implementation, but just the testing branch. I basically drop every third and fourth update, to simulate missing updates. If one or both of these (omitted) updates are at the end of all the updates (like the last emoji reaction), they will never be applied, because there is no later update that triggers the GetMissingOnyxMessages flow.

In the testing branch in applyOnyxUpdatesReliably if you set the shouldOmitUpdate flag to false, this issue should not happen anymore. Can you confirm that?

@hungvu193
Copy link
Contributor

hungvu193 commented Apr 27, 2024

In the testing branch in applyOnyxUpdatesReliably if you set the shouldOmitUpdate flag to false, this issue should not happen anymore. Can you confirm that?

you mean shouldRunSync to false right?

export default function applyOnyxUpdatesReliably(updates: OnyxUpdatesFromServer, shouldRunSync = false, clientLastUpdateID = 0) {

Oh I saw it 🤦 I checked out this branch instead of testing branch.

@danieldoglas
Copy link
Contributor

Nice. Seems like this is almost there... @hungvu193 @eh2077 you think we're good to merge this?

@hungvu193
Copy link
Contributor

Nice. Seems like this is almost there... @hungvu193 @eh2077 you think we're good to merge this?

Sounds good to me 😄

eh2077

This comment was marked as resolved.

@chrispader
Copy link
Contributor Author

If only resetting deferredUpdatesProxy.deferredUpdates after calling method detectGapsAndSplit, the two tests are also passed.

i'm not sure i understand what you mean. what scneria would resetting deferred updates after detectGapsAnsSplit simulate?

The deferred updates should/can only be reset by the OnyxUpdateManager.

Do you mean we should protect this export, so manipulation from the outside is not possible?

@eh2077
Copy link
Contributor

eh2077 commented Apr 29, 2024

@chrispader thanks for your comment. Sorry, please omit my comments as I overlooked and misunderstood something.

@melvin-bot melvin-bot bot requested a review from danieldoglas April 29, 2024 11:00
@eh2077
Copy link
Contributor

eh2077 commented Apr 29, 2024

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
Android: mWeb Chrome

NA

iOS: Native

NA

iOS: mWeb Safari

NA

MacOS: Chrome / Safari
Screen.Recording.2024-04-25.at.17.50.04.mp4
0-test-2.mp4
MacOS: Desktop

NA

@danieldoglas danieldoglas merged commit cad52d9 into Expensify:main Apr 30, 2024
16 of 20 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented May 1, 2024

🚀 Deployed to staging by https://github.com/danieldoglas in version: 1.4.69-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@kbecciv
Copy link

kbecciv commented May 1, 2024

@chrispader @danieldoglas QA team is blocked to verify this PR, having the following error when trying to run the code snippet in console. Can you please verify internally?
Screenshot 2024-05-01 at 9 23 17 at night

@francoisl
Copy link
Contributor

The QA steps shouldn't involve commenting code out, can you guys think of an alternative way to QA this internally please?

@danieldoglas
Copy link
Contributor

@kbecciv Updated the tests

@kbecciv
Copy link

kbecciv commented May 2, 2024

@danieldoglas

This PR is failing because of issue #38748 - there are multiple GetMissingOnyxMessages requests in request tab.

The issue is checked in: Web and Desktop

image

1714647274460.Screen_Recording_2024-05-02_at_1.46.33_in_the_afternoon.mp4

@OSBotify
Copy link
Contributor

OSBotify commented May 2, 2024

🚀 Deployed to production by https://github.com/Beamanator in version: 1.4.69-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@danieldoglas
Copy link
Contributor

That actually seems correct - it did 3, but one at a time, not 3 at the same time.

@chrispader
Copy link
Contributor Author

@danieldoglas i didn't follow recent conversations 100%, but i think the implementation in this PR is still valid and there's no need to fix anything right now, right?

@danieldoglas
Copy link
Contributor

Yep, this is all correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants