From 900eaed3671fd339324ecaada6c589a4cbec44c3 Mon Sep 17 00:00:00 2001 From: Github Date: Mon, 4 Mar 2024 12:11:32 +0100 Subject: [PATCH 1/2] Redesign Reassure tests for getOrderedReportIDs --- tests/perf-test/SidebarUtils.perf-test.ts | 18 +++++++++++++----- tests/utils/collections/reportActions.ts | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index 2b2bdbc6b57a..c8a46caf7f23 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -1,3 +1,4 @@ +import {rand} from '@ngneat/falso'; import type {OnyxCollection} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import {measureFunction} from 'reassure'; @@ -13,14 +14,20 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject'; import createCollection from '../utils/collections/createCollection'; import createPersonalDetails from '../utils/collections/personalDetails'; import createRandomPolicy from '../utils/collections/policies'; -import createRandomReportAction from '../utils/collections/reportActions'; +import createRandomReportAction, {getRandomDate} from '../utils/collections/reportActions'; import createRandomReport from '../utils/collections/reports'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; -const getMockedReports = (length = 500) => +const getMockedReports = (length = 1000) => createCollection( (item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, - (index) => createRandomReport(index), + (index) => ({ + ...createRandomReport(index), + type: rand(Object.values(CONST.REPORT.TYPE)), + lastVisibleActionCreated: getRandomDate(), + statusNum: index % 5 ? 0 : CONST.REPORT.STATUS_NUM.CLOSED, + stateNum: index % 5 ? 0 : CONST.REPORT.STATE_NUM.APPROVED, + }), length, ); @@ -34,7 +41,7 @@ const personalDetails = createCollection( (index) => createPersonalDetails(index), ); -const mockedResponseMap = getMockedReports(1000) as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}`, Report>; +const mockedResponseMap = getMockedReports() as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}`, Report>; describe('SidebarUtils', () => { beforeAll(() => { @@ -45,6 +52,7 @@ describe('SidebarUtils', () => { Onyx.multiSet({ ...mockedResponseMap, + [ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails, }); }); @@ -52,7 +60,7 @@ describe('SidebarUtils', () => { Onyx.clear(); }); - test('[SidebarUtils] getOptionData on 1k reports', async () => { + test('[SidebarUtils] getOptionData on 1 reports', async () => { const report = createRandomReport(1); const preferredLocale = 'en'; const policy = createRandomPolicy(1); diff --git a/tests/utils/collections/reportActions.ts b/tests/utils/collections/reportActions.ts index bb14a2c7a41b..dcfa896f1ae4 100644 --- a/tests/utils/collections/reportActions.ts +++ b/tests/utils/collections/reportActions.ts @@ -80,3 +80,5 @@ export default function createRandomReportAction(index: number): ReportAction { isAttachment: randBoolean(), }; } + +export {getRandomDate}; From cae01b2c87fe2ce8f5dc371b4ad9bf7cec3325af Mon Sep 17 00:00:00 2001 From: Github Date: Tue, 5 Mar 2024 18:09:48 +0100 Subject: [PATCH 2/2] resolve conflicts --- tests/perf-test/SidebarUtils.perf-test.ts | 131 +++++++++++++--------- 1 file changed, 76 insertions(+), 55 deletions(-) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index c8a46caf7f23..a57eaf593cff 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -18,18 +18,22 @@ import createRandomReportAction, {getRandomDate} from '../utils/collections/repo import createRandomReport from '../utils/collections/reports'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; -const getMockedReports = (length = 1000) => - createCollection( - (item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, - (index) => ({ - ...createRandomReport(index), - type: rand(Object.values(CONST.REPORT.TYPE)), - lastVisibleActionCreated: getRandomDate(), - statusNum: index % 5 ? 0 : CONST.REPORT.STATUS_NUM.CLOSED, - stateNum: index % 5 ? 0 : CONST.REPORT.STATE_NUM.APPROVED, - }), - length, - ); +const REPORTS_COUNT = 15000; +const REPORT_TRESHOLD = 5; +const PERSONAL_DETAILS_LIST_COUNT = 1000; + +const allReports = createCollection( + (item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, + (index) => ({ + ...createRandomReport(index), + type: rand(Object.values(CONST.REPORT.TYPE)), + lastVisibleActionCreated: getRandomDate(), + // add status and state to every 5th report to mock nonarchived reports + statusNum: index % REPORT_TRESHOLD ? 0 : CONST.REPORT.STATUS_NUM.CLOSED, + stateNum: index % REPORT_TRESHOLD ? 0 : CONST.REPORT.STATE_NUM.APPROVED, + }), + REPORTS_COUNT, +); const reportActions = createCollection( (item) => `${item.reportActionID}`, @@ -39,9 +43,48 @@ const reportActions = createCollection( const personalDetails = createCollection( (item) => item.accountID, (index) => createPersonalDetails(index), + PERSONAL_DETAILS_LIST_COUNT, +); + +const policies = createCollection( + (item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`, + (index) => createRandomPolicy(index), ); -const mockedResponseMap = getMockedReports() as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}`, Report>; +const mockedBetas = Object.values(CONST.BETAS); + +const allReportActions = Object.fromEntries( + Object.keys(reportActions).map((key) => [ + `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${key}`, + { + [reportActions[key].reportActionID]: { + errors: reportActions[key].errors ?? [], + message: [ + { + moderationDecision: { + decision: reportActions[key].message?.[0]?.moderationDecision?.decision, + }, + }, + ], + reportActionID: reportActions[key].reportActionID, + }, + }, + ]), +) as unknown as OnyxCollection; + +const currentReportId = '1'; +const transactionViolations = {} as OnyxCollection; + +const reportKeys = Object.keys(allReports); +const reportIDsWithErrors = reportKeys.reduce((errorsMap, reportKey) => { + const report = allReports[reportKey]; + const allReportsActions = allReportActions?.[reportKey.replace('report_', 'reportActions_')] ?? null; + const errors = OptionsListUtils.getAllReportErrors(report, allReportsActions) || {}; + if (isEmptyObject(errors)) { + return errorsMap; + } + return {...errorsMap, [reportKey.replace('report_', '')]: errors}; +}, {}); describe('SidebarUtils', () => { beforeAll(() => { @@ -51,7 +94,6 @@ describe('SidebarUtils', () => { }); Onyx.multiSet({ - ...mockedResponseMap, [ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails, }); }); @@ -60,7 +102,7 @@ describe('SidebarUtils', () => { Onyx.clear(); }); - test('[SidebarUtils] getOptionData on 1 reports', async () => { + test('[SidebarUtils] getOptionData', async () => { const report = createRandomReport(1); const preferredLocale = 'en'; const policy = createRandomPolicy(1); @@ -81,54 +123,33 @@ describe('SidebarUtils', () => { ); }); - test('[SidebarUtils] getOrderedReportIDs on 1k reports', async () => { - const currentReportId = '1'; - const allReports = getMockedReports(); - const betas = [CONST.BETAS.DEFAULT_ROOMS]; - const transactionViolations = {} as OnyxCollection; - - const policies = createCollection( - (item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`, - (index) => createRandomPolicy(index), + test('[SidebarUtils] getOrderedReportIDs on 15k reports for default priorityMode', async () => { + await waitForBatchedUpdates(); + await measureFunction(() => + SidebarUtils.getOrderedReportIDs( + currentReportId, + allReports, + mockedBetas, + policies, + CONST.PRIORITY_MODE.DEFAULT, + allReportActions, + transactionViolations, + undefined, + undefined, + reportIDsWithErrors, + ), ); + }); - const allReportActions = Object.fromEntries( - Object.keys(reportActions).map((key) => [ - key, - { - [reportActions[key].reportActionID]: { - errors: reportActions[key].errors ?? [], - message: [ - { - moderationDecision: { - decision: reportActions[key].message?.[0]?.moderationDecision?.decision, - }, - }, - ], - }, - }, - ]), - ) as unknown as OnyxCollection; - - const reportKeys = Object.keys(allReports); - const reportIDsWithErrors = reportKeys.reduce((errorsMap, reportKey) => { - const report = allReports[reportKey]; - const allReportsActions = allReportActions?.[reportKey.replace('report_', 'reportActions_')] ?? null; - const errors = OptionsListUtils.getAllReportErrors(report, allReportsActions) || {}; - if (isEmptyObject(errors)) { - return errorsMap; - } - return {...errorsMap, [reportKey.replace('report_', '')]: errors}; - }, {}); - + test('[SidebarUtils] getOrderedReportIDs on 15k reports for GSD priorityMode', async () => { await waitForBatchedUpdates(); await measureFunction(() => SidebarUtils.getOrderedReportIDs( currentReportId, allReports, - betas, + mockedBetas, policies, - CONST.PRIORITY_MODE.DEFAULT, + CONST.PRIORITY_MODE.GSD, allReportActions, transactionViolations, undefined,