-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[NoQA] test(reassure): get last visible action #30482
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 7 commits into
Expensify:main
from
adhorodyski:reassure/get-last-visible-action
Nov 1, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
61f8488
chore: add perf test for getLastVisibleAction with 10k reportActions
adhorodyski 4ea9fb6
Merge branch 'Expensify:main' into reassure/get-last-visible-action
adhorodyski 91e1f28
chore: add perf test for getLastVisibleAction with actionsToMerge
adhorodyski 14c6981
Merge branch 'Expensify:main' into reassure/get-last-visible-action
adhorodyski e33e0d9
Merge branch 'Expensify:main' into reassure/get-last-visible-action
adhorodyski 1fb0e5b
chore: satisfy linter, remove redundnat double underscore placeholder
adhorodyski f8b184a
chore: apply code review updates for naming unused parameters
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import Onyx from 'react-native-onyx'; | ||
| import {measureFunction} from 'reassure'; | ||
| import _ from 'underscore'; | ||
| import CONST from '../../src/CONST'; | ||
| import * as ReportActionsUtils from '../../src/libs/ReportActionsUtils'; | ||
| import ONYXKEYS from '../../src/ONYXKEYS'; | ||
| import * as LHNTestUtils from '../utils/LHNTestUtils'; | ||
| import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
|
|
||
| jest.setTimeout(60000); | ||
|
|
||
| beforeAll(() => | ||
| Onyx.init({ | ||
| keys: ONYXKEYS, | ||
| safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], | ||
| registerStorageEventListener: () => {}, | ||
| }), | ||
| ); | ||
|
|
||
| // Clear out Onyx after each test so that each test starts with a clean slate | ||
| afterEach(() => { | ||
| Onyx.clear(); | ||
| }); | ||
|
|
||
| const getMockedReportActionsMap = (reportsLength = 10, actionsPerReportLength = 100) => { | ||
| const mockReportActions = Array.from({length: actionsPerReportLength}, (_reportAction, i) => { | ||
| const reportActionKey = i + 1; | ||
| const email = `actor+${reportActionKey}@mail.com`; | ||
| const reportAction = LHNTestUtils.getFakeReportAction(email); | ||
|
|
||
| return {[reportActionKey]: reportAction}; | ||
| }); | ||
|
|
||
| const reportKeysMap = Array.from({length: reportsLength}, (_report, i) => { | ||
| const key = i + 1; | ||
|
|
||
| return {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${key}`]: _.assign({}, ...mockReportActions)}; | ||
| }); | ||
|
|
||
| return _.assign({}, ...reportKeysMap); | ||
| }; | ||
|
|
||
| const mockedReportActionsMap = getMockedReportActionsMap(2, 10000); | ||
|
|
||
| /** | ||
| * This function will be executed 20 times and the average time will be used on the comparison. | ||
| * It will fail based on the CI configuration around Reassure: | ||
| * @see /.github/workflows/reassurePerformanceTests.yml | ||
| * | ||
| * Max deviation on the duration is set to 20% at the time of writing. | ||
| * | ||
| * More on the measureFunction API: | ||
| * @see https://callstack.github.io/reassure/docs/api#measurefunction-function | ||
| */ | ||
| test('getLastVisibleAction on 10k reportActions', async () => { | ||
| const reportId = '1'; | ||
|
|
||
| await Onyx.multiSet({ | ||
| ...mockedReportActionsMap, | ||
| }); | ||
| await waitForBatchedUpdates(); | ||
| await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId), {runs: 20}); | ||
| }); | ||
|
|
||
| test('getLastVisibleAction on 10k reportActions with actionsToMerge', async () => { | ||
| const reportId = '1'; | ||
| const parentReportActionId = '1'; | ||
| const fakeParentAction = mockedReportActionsMap[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportId}`][parentReportActionId]; | ||
| const actionsToMerge = { | ||
| [parentReportActionId]: { | ||
| pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, | ||
| previousMessage: fakeParentAction.message, | ||
| message: [ | ||
| { | ||
| translationKey: '', | ||
| type: 'COMMENT', | ||
| html: '', | ||
| text: '', | ||
| isEdited: true, | ||
| isDeletedParentAction: true, | ||
| }, | ||
| ], | ||
| errors: null, | ||
| linkMetaData: [], | ||
| }, | ||
| }; | ||
|
|
||
| await Onyx.multiSet({ | ||
| ...mockedReportActionsMap, | ||
| }); | ||
| await waitForBatchedUpdates(); | ||
| await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId, actionsToMerge), {runs: 20}); | ||
| }); | ||
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
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.