From 243396af3879522cfd27858741a2a0941f9d47df Mon Sep 17 00:00:00 2001 From: Github Date: Mon, 27 Nov 2023 10:42:29 +0100 Subject: [PATCH] add timeouts and runs improvements --- .../perf-test/ReportActionsUtils.perf-test.js | 91 ------------------- .../perf-test/ReportActionsUtils.perf-test.ts | 20 ++-- 2 files changed, 10 insertions(+), 101 deletions(-) delete mode 100644 tests/perf-test/ReportActionsUtils.perf-test.js diff --git a/tests/perf-test/ReportActionsUtils.perf-test.js b/tests/perf-test/ReportActionsUtils.perf-test.js deleted file mode 100644 index 8e9f5570d5d8..000000000000 --- a/tests/perf-test/ReportActionsUtils.perf-test.js +++ /dev/null @@ -1,91 +0,0 @@ -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'; - -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}); -}); diff --git a/tests/perf-test/ReportActionsUtils.perf-test.ts b/tests/perf-test/ReportActionsUtils.perf-test.ts index 36b99b789eb0..a52e75c8b75f 100644 --- a/tests/perf-test/ReportActionsUtils.perf-test.ts +++ b/tests/perf-test/ReportActionsUtils.perf-test.ts @@ -8,8 +8,6 @@ import createCollection from '../utils/collections/createCollection'; import createRandomReportAction from '../utils/collections/reportActions'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; -jest.setTimeout(60000); - beforeAll(() => Onyx.init({ keys: ONYXKEYS, @@ -48,6 +46,8 @@ const reportActions = createCollection( const reportId = '1'; +const runs = CONST.PERFORMANCE_TESTS.RUNS; + /** * 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: @@ -64,7 +64,7 @@ test('getLastVisibleAction on 10k reportActions', async () => { }); await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId), {runs: 20}); + await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId), {runs}); }); test('getLastVisibleAction on 10k reportActions with actionsToMerge', async () => { @@ -93,7 +93,7 @@ test('getLastVisibleAction on 10k reportActions with actionsToMerge', async () = ...mockedReportActionsMap, }); await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId, actionsToMerge), {runs: 20}); + await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId, actionsToMerge), {runs}); }); test('getMostRecentIOURequestActionID on 10k ReportActions', async () => { @@ -102,7 +102,7 @@ test('getMostRecentIOURequestActionID on 10k ReportActions', async () => { ...mockedReportActionsMap, }); await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getMostRecentIOURequestActionID(reportActionsArray), {runs: 20}); + await measureFunction(() => ReportActionsUtils.getMostRecentIOURequestActionID(reportActionsArray), {runs}); }); test('getLastVisibleMessage on 10k ReportActions', async () => { @@ -110,7 +110,7 @@ test('getLastVisibleMessage on 10k ReportActions', async () => { ...mockedReportActionsMap, }); await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId), {runs: 20}); + await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId), {runs}); }); test('getLastVisibleMessage on 10k ReportActions with actionsToMerge', async () => { @@ -139,7 +139,7 @@ test('getLastVisibleMessage on 10k ReportActions with actionsToMerge', async () ...mockedReportActionsMap, }); await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId, actionsToMerge), {runs: 20}); + await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId, actionsToMerge), {runs}); }); test('getSortedReportActionsForDisplay on 10k ReportActions', async () => { @@ -147,7 +147,7 @@ test('getSortedReportActionsForDisplay on 10k ReportActions', async () => { ...mockedReportActionsMap, }); await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getSortedReportActionsForDisplay(reportActions), {runs: 20}); + await measureFunction(() => ReportActionsUtils.getSortedReportActionsForDisplay(reportActions), {runs}); }); test('getLastClosedReportAction on 10k ReportActions', async () => { @@ -155,7 +155,7 @@ test('getLastClosedReportAction on 10k ReportActions', async () => { ...mockedReportActionsMap, }); await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getLastClosedReportAction(reportActions), {runs: 20}); + await measureFunction(() => ReportActionsUtils.getLastClosedReportAction(reportActions), {runs}); }); test('getMostRecentReportActionLastModified', async () => { @@ -163,5 +163,5 @@ test('getMostRecentReportActionLastModified', async () => { ...mockedReportActionsMap, }); await waitForBatchedUpdates(); - await measureFunction(() => ReportActionsUtils.getMostRecentReportActionLastModified(), {runs: 20}); + await measureFunction(() => ReportActionsUtils.getMostRecentReportActionLastModified(), {runs}); });