From 49bf3e6d546872a39bcb0e1f92e730d3e12d110d Mon Sep 17 00:00:00 2001 From: Shridhar Goel <35566748+ShridharGoel@users.noreply.github.com> Date: Thu, 14 Mar 2024 09:40:14 +0530 Subject: [PATCH 01/16] Add performance tests for getMemberAccountIDsForWorkspace --- tests/perf-test/PolicyUtils.perf-test.js | 61 ++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/perf-test/PolicyUtils.perf-test.js diff --git a/tests/perf-test/PolicyUtils.perf-test.js b/tests/perf-test/PolicyUtils.perf-test.js new file mode 100644 index 000000000000..c6651ad49b4a --- /dev/null +++ b/tests/perf-test/PolicyUtils.perf-test.js @@ -0,0 +1,61 @@ +import {measureFunction} from 'reassure'; +import {getMemberAccountIDsForWorkspace} from "@libs/PolicyUtils"; + +describe('[PolicyUtils] Performance tests for getMemberAccountIDsForWorkspace', () => { + + test('With multiple members without errors and login details', async () => { + const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {}}])); + const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, { + accountID: 12345, + firstName: 'First', + lastName: 'Last', + displayName: 'First Last', + validated: true, + phoneNumber: 1234567890, + login: `user${i}@example.com` + }])); + + await measureFunction(() => getMemberAccountIDsForWorkspace( + policyMembers, + personalDetails + )); + }) + + test('With multiple members with errors and without login details', async () => { + const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {someError: true}}])); + const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); + + await measureFunction(() => getMemberAccountIDsForWorkspace( + policyMembers, + personalDetails + )); + }) + + test('With multiple members with errors and with login details', async () => { + const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {someError: true}}])); + const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, { + accountID: 12345, + firstName: 'First', + lastName: 'Last', + displayName: 'First Last', + validated: true, + phoneNumber: 1234567890, + login: `user${i}@example.com` + }])); + + await measureFunction(() => getMemberAccountIDsForWorkspace( + policyMembers, + personalDetails + )); + }) + + test('With multiple members without errors and without login details', async () => { + const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {}}])); + const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); + + await measureFunction(() => getMemberAccountIDsForWorkspace( + policyMembers, + personalDetails + )); + }) +}); From 3cbb3093ceed8d5e070a0b55700d953c6884c091 Mon Sep 17 00:00:00 2001 From: Shridhar Goel <35566748+ShridharGoel@users.noreply.github.com> Date: Thu, 14 Mar 2024 13:28:30 +0530 Subject: [PATCH 02/16] Update PolicyUtils.perf-test.js --- tests/perf-test/PolicyUtils.perf-test.js | 81 ++++++++++++------------ 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/tests/perf-test/PolicyUtils.perf-test.js b/tests/perf-test/PolicyUtils.perf-test.js index c6651ad49b4a..ad0e5d0fd84e 100644 --- a/tests/perf-test/PolicyUtils.perf-test.js +++ b/tests/perf-test/PolicyUtils.perf-test.js @@ -1,61 +1,58 @@ import {measureFunction} from 'reassure'; -import {getMemberAccountIDsForWorkspace} from "@libs/PolicyUtils"; +import {getMemberAccountIDsForWorkspace} from '@libs/PolicyUtils'; describe('[PolicyUtils] Performance tests for getMemberAccountIDsForWorkspace', () => { - test('With multiple members without errors and login details', async () => { const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {}}])); - const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, { - accountID: 12345, - firstName: 'First', - lastName: 'Last', - displayName: 'First Last', - validated: true, - phoneNumber: 1234567890, - login: `user${i}@example.com` - }])); - - await measureFunction(() => getMemberAccountIDsForWorkspace( - policyMembers, - personalDetails - )); - }) + const personalDetails = Object.fromEntries( + Array.from({length: 10000}, (_, i) => [ + `${i}`, + { + accountID: 12345, + firstName: 'First', + lastName: 'Last', + displayName: 'First Last', + validated: true, + phoneNumber: 1234567890, + login: `test${i}@example.com`, + }, + ]), + ); + + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); test('With multiple members with errors and without login details', async () => { const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {someError: true}}])); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); - await measureFunction(() => getMemberAccountIDsForWorkspace( - policyMembers, - personalDetails - )); - }) + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); test('With multiple members with errors and with login details', async () => { const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {someError: true}}])); - const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, { - accountID: 12345, - firstName: 'First', - lastName: 'Last', - displayName: 'First Last', - validated: true, - phoneNumber: 1234567890, - login: `user${i}@example.com` - }])); - - await measureFunction(() => getMemberAccountIDsForWorkspace( - policyMembers, - personalDetails - )); - }) + const personalDetails = Object.fromEntries( + Array.from({length: 10000}, (_, i) => [ + `${i}`, + { + accountID: 12345, + firstName: 'First', + lastName: 'Last', + displayName: 'First Last', + validated: true, + phoneNumber: 1234567890, + login: `user${i}@example.com`, + }, + ]), + ); + + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); test('With multiple members without errors and without login details', async () => { const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {}}])); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); - await measureFunction(() => getMemberAccountIDsForWorkspace( - policyMembers, - personalDetails - )); - }) + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); }); From d3ac36948b048d1eb316263274af7cd912c41c3f Mon Sep 17 00:00:00 2001 From: Shridhar Goel <35566748+ShridharGoel@users.noreply.github.com> Date: Thu, 14 Mar 2024 22:23:45 +0530 Subject: [PATCH 03/16] Update PolicyUtils.perf-test.js --- tests/perf-test/PolicyUtils.perf-test.js | 51 +++++++----------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/tests/perf-test/PolicyUtils.perf-test.js b/tests/perf-test/PolicyUtils.perf-test.js index ad0e5d0fd84e..20e685600f8d 100644 --- a/tests/perf-test/PolicyUtils.perf-test.js +++ b/tests/perf-test/PolicyUtils.perf-test.js @@ -1,56 +1,35 @@ import {measureFunction} from 'reassure'; import {getMemberAccountIDsForWorkspace} from '@libs/PolicyUtils'; +import PolicyMember from '@src/types/onyx/PolicyMember'; +import createCollection from '../utils/collections/createCollection'; +import createPersonalDetails from '../utils/collections/personalDetails'; +import createRandomPolicy from '../utils/collections/policies'; +import createRandomPolicyMember from '../utils/collections/policyMembers'; describe('[PolicyUtils] Performance tests for getMemberAccountIDsForWorkspace', () => { - test('With multiple members without errors and login details', async () => { - const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {}}])); - const personalDetails = Object.fromEntries( - Array.from({length: 10000}, (_, i) => [ - `${i}`, - { - accountID: 12345, - firstName: 'First', - lastName: 'Last', - displayName: 'First Last', - validated: true, - phoneNumber: 1234567890, - login: `test${i}@example.com`, - }, - ]), - ); + test('With multiple members with personal details and policy members', async () => { + const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); + const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, createPersonalDetails(i)])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); - test('With multiple members with errors and without login details', async () => { - const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {someError: true}}])); + test('With multiple members with empty personal details and with errors in policy members', async () => { + const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index), errors: {someError: true}})); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); - test('With multiple members with errors and with login details', async () => { - const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {someError: true}}])); - const personalDetails = Object.fromEntries( - Array.from({length: 10000}, (_, i) => [ - `${i}`, - { - accountID: 12345, - firstName: 'First', - lastName: 'Last', - displayName: 'First Last', - validated: true, - phoneNumber: 1234567890, - login: `user${i}@example.com`, - }, - ]), - ); + test('With multiple members with personal details and with errors in policy members', async () => { + const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicy(index), errors: {someError: true}})); + const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, createPersonalDetails(i)])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); - test('With multiple members without errors and without login details', async () => { - const policyMembers = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {errors: {}}])); + test('With multiple members with empty personal details and with policy members', async () => { + const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); From b549f7447929d32b37d5628ed63eab0c922443c2 Mon Sep 17 00:00:00 2001 From: Shridhar Goel <35566748+ShridharGoel@users.noreply.github.com> Date: Thu, 14 Mar 2024 22:28:46 +0530 Subject: [PATCH 04/16] Update --- tests/perf-test/PolicyUtils.perf-test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/perf-test/PolicyUtils.perf-test.js b/tests/perf-test/PolicyUtils.perf-test.js index 20e685600f8d..83aa6515356d 100644 --- a/tests/perf-test/PolicyUtils.perf-test.js +++ b/tests/perf-test/PolicyUtils.perf-test.js @@ -8,28 +8,28 @@ import createRandomPolicyMember from '../utils/collections/policyMembers'; describe('[PolicyUtils] Performance tests for getMemberAccountIDsForWorkspace', () => { test('With multiple members with personal details and policy members', async () => { - const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); + const policyMembers = createCollection((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, createPersonalDetails(i)])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); test('With multiple members with empty personal details and with errors in policy members', async () => { - const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index), errors: {someError: true}})); + const policyMembers = createCollection((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index), errors: {someError: true}})); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); test('With multiple members with personal details and with errors in policy members', async () => { - const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicy(index), errors: {someError: true}})); + const policyMembers = createCollection((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicy(index), errors: {someError: true}})); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, createPersonalDetails(i)])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); test('With multiple members with empty personal details and with policy members', async () => { - const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); + const policyMembers = createCollection((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); From f77b6eb5c96074b49eedf2abbe024dbdc05da85d Mon Sep 17 00:00:00 2001 From: Shridhar Goel <35566748+ShridharGoel@users.noreply.github.com> Date: Thu, 14 Mar 2024 22:52:24 +0530 Subject: [PATCH 05/16] Add policyMembers.ts in utils --- tests/utils/collections/policyMembers.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/utils/collections/policyMembers.ts diff --git a/tests/utils/collections/policyMembers.ts b/tests/utils/collections/policyMembers.ts new file mode 100644 index 000000000000..a198ef0f3bd5 --- /dev/null +++ b/tests/utils/collections/policyMembers.ts @@ -0,0 +1,9 @@ +import {randWord} from '@ngneat/falso'; +import PolicyMember from '@src/types/onyx/PolicyMember'; + +export default function createRandomPolicyMember(): PolicyMember { + return { + role: randWord(), + errors: {}, + }; +} From 97bd870c3ba8d5dab20fee2a1ff3a68a8c4fd3b1 Mon Sep 17 00:00:00 2001 From: Shridhar Goel <35566748+ShridharGoel@users.noreply.github.com> Date: Thu, 14 Mar 2024 23:56:52 +0530 Subject: [PATCH 06/16] Update policyMembers.ts --- tests/utils/collections/policyMembers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils/collections/policyMembers.ts b/tests/utils/collections/policyMembers.ts index a198ef0f3bd5..b44cd7a3e3c6 100644 --- a/tests/utils/collections/policyMembers.ts +++ b/tests/utils/collections/policyMembers.ts @@ -1,5 +1,5 @@ import {randWord} from '@ngneat/falso'; -import PolicyMember from '@src/types/onyx/PolicyMember'; +import type PolicyMember from '@src/types/onyx/PolicyMember'; export default function createRandomPolicyMember(): PolicyMember { return { From 656792848df2c90c09000f2ff8f6a421c8597bd7 Mon Sep 17 00:00:00 2001 From: Shridhar Goel <35566748+ShridharGoel@users.noreply.github.com> Date: Fri, 15 Mar 2024 00:04:23 +0530 Subject: [PATCH 07/16] Update --- tests/perf-test/PolicyUtils.perf-test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/perf-test/PolicyUtils.perf-test.js b/tests/perf-test/PolicyUtils.perf-test.js index 83aa6515356d..20e685600f8d 100644 --- a/tests/perf-test/PolicyUtils.perf-test.js +++ b/tests/perf-test/PolicyUtils.perf-test.js @@ -8,28 +8,28 @@ import createRandomPolicyMember from '../utils/collections/policyMembers'; describe('[PolicyUtils] Performance tests for getMemberAccountIDsForWorkspace', () => { test('With multiple members with personal details and policy members', async () => { - const policyMembers = createCollection((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); + const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, createPersonalDetails(i)])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); test('With multiple members with empty personal details and with errors in policy members', async () => { - const policyMembers = createCollection((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index), errors: {someError: true}})); + const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index), errors: {someError: true}})); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); test('With multiple members with personal details and with errors in policy members', async () => { - const policyMembers = createCollection((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicy(index), errors: {someError: true}})); + const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicy(index), errors: {someError: true}})); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, createPersonalDetails(i)])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); test('With multiple members with empty personal details and with policy members', async () => { - const policyMembers = createCollection((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); + const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); From 64e94cc292e09796948ad0ff99a54d50de78878d Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Sat, 16 Mar 2024 00:10:59 +0530 Subject: [PATCH 08/16] Update with suggested changes --- tests/perf-test/PolicyUtils.perf-test.ts | 54 ++++++++++++++++++++++ tests/utils/collections/personalDetails.ts | 7 ++- tests/utils/collections/policyMembers.ts | 6 +-- 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 tests/perf-test/PolicyUtils.perf-test.ts diff --git a/tests/perf-test/PolicyUtils.perf-test.ts b/tests/perf-test/PolicyUtils.perf-test.ts new file mode 100644 index 000000000000..7728e7548fe0 --- /dev/null +++ b/tests/perf-test/PolicyUtils.perf-test.ts @@ -0,0 +1,54 @@ +import {measureFunction} from 'reassure'; +import {getMemberAccountIDsForWorkspace} from '@libs/PolicyUtils'; +import type {PersonalDetails, PolicyMember} from '@src/types/onyx'; +import createCollection from '../utils/collections/createCollection'; +import createPersonalDetails from '../utils/collections/personalDetails'; +import createRandomPolicyMember from '../utils/collections/policyMembers'; + +describe('[PolicyUtils] Performance tests for getMemberAccountIDsForWorkspace', () => { + test('With multiple members with personal details and policy members', async () => { + const policyMembers: Record = createCollection( + (_, index: number) => `policyMembers_${index}`, + () => createRandomPolicyMember(), + ); + const personalDetails: Record = createCollection((_, index: number) => `personalDetails_${index}`, createPersonalDetails); + + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); + + test('With multiple members with empty personal details and with errors in policy members', async () => { + const policyMembers: Record = createCollection( + (_, index: number) => `policyMembers_${index}`, + () => createRandomPolicyMember(true), + ); + const personalDetails: Record = createCollection( + (_, index: number) => `personalDetails_${index}`, + (index: number) => createPersonalDetails(index, true), + ); + + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); + + test('With multiple members with personal details and with errors in policy members', async () => { + const policyMembers: Record = createCollection( + (_, index: number) => `policyMembers_${index}`, + () => createRandomPolicyMember(true), + ); + const personalDetails: Record = createCollection((_, index: number) => `personalDetails_${index}`, createPersonalDetails); + + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); + + test('With multiple members with empty personal details and with policy members', async () => { + const policyMembers: Record = createCollection( + (_, index: number) => `policyMembers_${index}`, + () => createRandomPolicyMember(), + ); + const personalDetails: Record = createCollection( + (_, index: number) => `personalDetails_${index}`, + (index: number) => createPersonalDetails(index, true), + ); + + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); +}); diff --git a/tests/utils/collections/personalDetails.ts b/tests/utils/collections/personalDetails.ts index 4fa8586aa08c..181fbb839209 100644 --- a/tests/utils/collections/personalDetails.ts +++ b/tests/utils/collections/personalDetails.ts @@ -1,7 +1,12 @@ import {randAvatar, randEmail, randWord} from '@ngneat/falso'; import type {PersonalDetails} from '@src/types/onyx'; -export default function createPersonalDetails(index: number): PersonalDetails { +export default function createPersonalDetails(index: number, shouldDetailsBeEmpty: boolean = false): PersonalDetails { + if (shouldDetailsBeEmpty) { + return { + accountID: index, + }; + } return { accountID: index, avatar: randAvatar(), diff --git a/tests/utils/collections/policyMembers.ts b/tests/utils/collections/policyMembers.ts index b44cd7a3e3c6..00001f8e90b1 100644 --- a/tests/utils/collections/policyMembers.ts +++ b/tests/utils/collections/policyMembers.ts @@ -1,9 +1,9 @@ import {randWord} from '@ngneat/falso'; -import type PolicyMember from '@src/types/onyx/PolicyMember'; +import type {PolicyMember} from '@src/types/onyx'; -export default function createRandomPolicyMember(): PolicyMember { +export default function createRandomPolicyMember(hasError: boolean = false): PolicyMember { return { role: randWord(), - errors: {}, + errors: hasError ? {someError: 'Message'} : {}, }; } From b93a7975026affa988553b06580e0e9669be5c51 Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Sat, 16 Mar 2024 00:12:06 +0530 Subject: [PATCH 09/16] Update with suggested changes --- tests/perf-test/PolicyUtils.perf-test.js | 37 ------------------------ 1 file changed, 37 deletions(-) delete mode 100644 tests/perf-test/PolicyUtils.perf-test.js diff --git a/tests/perf-test/PolicyUtils.perf-test.js b/tests/perf-test/PolicyUtils.perf-test.js deleted file mode 100644 index 20e685600f8d..000000000000 --- a/tests/perf-test/PolicyUtils.perf-test.js +++ /dev/null @@ -1,37 +0,0 @@ -import {measureFunction} from 'reassure'; -import {getMemberAccountIDsForWorkspace} from '@libs/PolicyUtils'; -import PolicyMember from '@src/types/onyx/PolicyMember'; -import createCollection from '../utils/collections/createCollection'; -import createPersonalDetails from '../utils/collections/personalDetails'; -import createRandomPolicy from '../utils/collections/policies'; -import createRandomPolicyMember from '../utils/collections/policyMembers'; - -describe('[PolicyUtils] Performance tests for getMemberAccountIDsForWorkspace', () => { - test('With multiple members with personal details and policy members', async () => { - const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); - const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, createPersonalDetails(i)])); - - await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); - }); - - test('With multiple members with empty personal details and with errors in policy members', async () => { - const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index), errors: {someError: true}})); - const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); - - await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); - }); - - test('With multiple members with personal details and with errors in policy members', async () => { - const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicy(index), errors: {someError: true}})); - const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, createPersonalDetails(i)])); - - await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); - }); - - test('With multiple members with empty personal details and with policy members', async () => { - const policyMembers = createCollection < PolicyMember > ((item, index) => `policyMembers_${index}`, (index) => ({...createRandomPolicyMember(index)})); - const personalDetails = Object.fromEntries(Array.from({length: 10000}, (_, i) => [`${i}`, {}])); - - await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); - }); -}); From be30f2b6741c7fc13a3c2792343e57d5841e22a3 Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Sat, 16 Mar 2024 00:12:56 +0530 Subject: [PATCH 10/16] Update --- tests/utils/collections/personalDetails.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/utils/collections/personalDetails.ts b/tests/utils/collections/personalDetails.ts index 181fbb839209..467008040a18 100644 --- a/tests/utils/collections/personalDetails.ts +++ b/tests/utils/collections/personalDetails.ts @@ -7,6 +7,7 @@ export default function createPersonalDetails(index: number, shouldDetailsBeEmpt accountID: index, }; } + return { accountID: index, avatar: randAvatar(), From f4e527e814aa5de2b737189d84c1009b888d670b Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Sat, 16 Mar 2024 00:23:19 +0530 Subject: [PATCH 11/16] Update --- tests/utils/collections/personalDetails.ts | 2 +- tests/utils/collections/policyMembers.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/collections/personalDetails.ts b/tests/utils/collections/personalDetails.ts index 467008040a18..5fb02407bffd 100644 --- a/tests/utils/collections/personalDetails.ts +++ b/tests/utils/collections/personalDetails.ts @@ -1,7 +1,7 @@ import {randAvatar, randEmail, randWord} from '@ngneat/falso'; import type {PersonalDetails} from '@src/types/onyx'; -export default function createPersonalDetails(index: number, shouldDetailsBeEmpty: boolean = false): PersonalDetails { +export default function createPersonalDetails(index: number, shouldDetailsBeEmpty = false): PersonalDetails { if (shouldDetailsBeEmpty) { return { accountID: index, diff --git a/tests/utils/collections/policyMembers.ts b/tests/utils/collections/policyMembers.ts index 00001f8e90b1..00a5f9d594cb 100644 --- a/tests/utils/collections/policyMembers.ts +++ b/tests/utils/collections/policyMembers.ts @@ -1,7 +1,7 @@ import {randWord} from '@ngneat/falso'; import type {PolicyMember} from '@src/types/onyx'; -export default function createRandomPolicyMember(hasError: boolean = false): PolicyMember { +export default function createRandomPolicyMember(hasError = false): PolicyMember { return { role: randWord(), errors: hasError ? {someError: 'Message'} : {}, From de413bf426eb57ebc6717cc61d14265d7812dab5 Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Sat, 16 Mar 2024 12:05:41 +0530 Subject: [PATCH 12/16] Update --- tests/perf-test/PolicyUtils.perf-test.ts | 46 +++++++++++++--------- tests/utils/collections/personalDetails.ts | 8 +--- tests/utils/collections/policyMembers.ts | 4 +- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/tests/perf-test/PolicyUtils.perf-test.ts b/tests/perf-test/PolicyUtils.perf-test.ts index 7728e7548fe0..f144be337e33 100644 --- a/tests/perf-test/PolicyUtils.perf-test.ts +++ b/tests/perf-test/PolicyUtils.perf-test.ts @@ -7,46 +7,56 @@ import createRandomPolicyMember from '../utils/collections/policyMembers'; describe('[PolicyUtils] Performance tests for getMemberAccountIDsForWorkspace', () => { test('With multiple members with personal details and policy members', async () => { - const policyMembers: Record = createCollection( - (_, index: number) => `policyMembers_${index}`, + const policyMembers = createCollection( + (_, index) => `policyMembers_${index}`, () => createRandomPolicyMember(), ); - const personalDetails: Record = createCollection((_, index: number) => `personalDetails_${index}`, createPersonalDetails); + const personalDetails = createCollection((_, index: number) => `personalDetails_${index}`, createPersonalDetails); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); test('With multiple members with empty personal details and with errors in policy members', async () => { - const policyMembers: Record = createCollection( - (_, index: number) => `policyMembers_${index}`, - () => createRandomPolicyMember(true), + const policyMembers = createCollection( + (_, index) => `policyMembers_${index}`, + () => ({ + ...createRandomPolicyMember(), + errors: {error: 'Error message'}, + }), ); - const personalDetails: Record = createCollection( - (_, index: number) => `personalDetails_${index}`, - (index: number) => createPersonalDetails(index, true), + const personalDetails = createCollection( + (_, index) => `personalDetails_${index}`, + (index) => ({ + accountID: index, + }), ); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); test('With multiple members with personal details and with errors in policy members', async () => { - const policyMembers: Record = createCollection( - (_, index: number) => `policyMembers_${index}`, - () => createRandomPolicyMember(true), + const policyMembers = createCollection( + (_, index) => `policyMembers_${index}`, + () => ({ + ...createRandomPolicyMember(), + errors: {error: 'Error message'}, + }), ); - const personalDetails: Record = createCollection((_, index: number) => `personalDetails_${index}`, createPersonalDetails); + const personalDetails = createCollection((_, index) => `personalDetails_${index}`, createPersonalDetails); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); test('With multiple members with empty personal details and with policy members', async () => { - const policyMembers: Record = createCollection( - (_, index: number) => `policyMembers_${index}`, + const policyMembers = createCollection( + (_, index) => `policyMembers_${index}`, () => createRandomPolicyMember(), ); - const personalDetails: Record = createCollection( - (_, index: number) => `personalDetails_${index}`, - (index: number) => createPersonalDetails(index, true), + const personalDetails = createCollection( + (_, index) => `personalDetails_${index}`, + (index) => ({ + accountID: index, + }), ); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); diff --git a/tests/utils/collections/personalDetails.ts b/tests/utils/collections/personalDetails.ts index 5fb02407bffd..4fa8586aa08c 100644 --- a/tests/utils/collections/personalDetails.ts +++ b/tests/utils/collections/personalDetails.ts @@ -1,13 +1,7 @@ import {randAvatar, randEmail, randWord} from '@ngneat/falso'; import type {PersonalDetails} from '@src/types/onyx'; -export default function createPersonalDetails(index: number, shouldDetailsBeEmpty = false): PersonalDetails { - if (shouldDetailsBeEmpty) { - return { - accountID: index, - }; - } - +export default function createPersonalDetails(index: number): PersonalDetails { return { accountID: index, avatar: randAvatar(), diff --git a/tests/utils/collections/policyMembers.ts b/tests/utils/collections/policyMembers.ts index 00a5f9d594cb..076c8ddb2d3d 100644 --- a/tests/utils/collections/policyMembers.ts +++ b/tests/utils/collections/policyMembers.ts @@ -1,9 +1,9 @@ import {randWord} from '@ngneat/falso'; import type {PolicyMember} from '@src/types/onyx'; -export default function createRandomPolicyMember(hasError = false): PolicyMember { +export default function createRandomPolicyMember(): PolicyMember { return { role: randWord(), - errors: hasError ? {someError: 'Message'} : {}, + errors: {}, }; } From cdf0a84c0e09edc372d275ce2c001e6df63814f8 Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Sat, 16 Mar 2024 12:07:39 +0530 Subject: [PATCH 13/16] Update --- tests/perf-test/PolicyUtils.perf-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/perf-test/PolicyUtils.perf-test.ts b/tests/perf-test/PolicyUtils.perf-test.ts index f144be337e33..6430791bcb66 100644 --- a/tests/perf-test/PolicyUtils.perf-test.ts +++ b/tests/perf-test/PolicyUtils.perf-test.ts @@ -11,7 +11,7 @@ describe('[PolicyUtils] Performance tests for getMemberAccountIDsForWorkspace', (_, index) => `policyMembers_${index}`, () => createRandomPolicyMember(), ); - const personalDetails = createCollection((_, index: number) => `personalDetails_${index}`, createPersonalDetails); + const personalDetails = createCollection((_, index) => `personalDetails_${index}`, createPersonalDetails); await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); From b6343bcf591b78a225058abd10fa1137a8e3f774 Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Sat, 16 Mar 2024 19:44:39 +0530 Subject: [PATCH 14/16] Add performance tests for getMemberAccountIDsForWorkspace --- tests/perf-test/PolicyUtils.perf-test.ts | 98 ++++++++++++------------ 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/tests/perf-test/PolicyUtils.perf-test.ts b/tests/perf-test/PolicyUtils.perf-test.ts index 6430791bcb66..5fffe7347b94 100644 --- a/tests/perf-test/PolicyUtils.perf-test.ts +++ b/tests/perf-test/PolicyUtils.perf-test.ts @@ -5,60 +5,62 @@ import createCollection from '../utils/collections/createCollection'; import createPersonalDetails from '../utils/collections/personalDetails'; import createRandomPolicyMember from '../utils/collections/policyMembers'; -describe('[PolicyUtils] Performance tests for getMemberAccountIDsForWorkspace', () => { - test('With multiple members with personal details and policy members', async () => { - const policyMembers = createCollection( - (_, index) => `policyMembers_${index}`, - () => createRandomPolicyMember(), - ); - const personalDetails = createCollection((_, index) => `personalDetails_${index}`, createPersonalDetails); +describe('PolicyUtils', () => { + describe('getMemberAccountIDsForWorkspace', () => { + test('500 policy members and full personal details', async () => { + const policyMembers = createCollection( + (_, index) => index, + () => createRandomPolicyMember(), + ); + const personalDetails = createCollection((_, index) => index, createPersonalDetails); - await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); - }); + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); - test('With multiple members with empty personal details and with errors in policy members', async () => { - const policyMembers = createCollection( - (_, index) => `policyMembers_${index}`, - () => ({ - ...createRandomPolicyMember(), - errors: {error: 'Error message'}, - }), - ); - const personalDetails = createCollection( - (_, index) => `personalDetails_${index}`, - (index) => ({ - accountID: index, - }), - ); + test('500 policy members and empty personal details', async () => { + const policyMembers = createCollection( + (_, index) => index, + () => createRandomPolicyMember(), + ); + const personalDetails = createCollection( + (_, index) => index, + (index) => ({ + accountID: index, + }), + ); - await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); - }); + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); - test('With multiple members with personal details and with errors in policy members', async () => { - const policyMembers = createCollection( - (_, index) => `policyMembers_${index}`, - () => ({ - ...createRandomPolicyMember(), - errors: {error: 'Error message'}, - }), - ); - const personalDetails = createCollection((_, index) => `personalDetails_${index}`, createPersonalDetails); + test('500 policy members with errors and full personal details', async () => { + const policyMembers = createCollection( + (_, index) => index, + () => ({ + ...createRandomPolicyMember(), + errors: {error: 'Error message'}, + }), + ); + const personalDetails = createCollection((_, index) => index, createPersonalDetails); - await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); - }); + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); - test('With multiple members with empty personal details and with policy members', async () => { - const policyMembers = createCollection( - (_, index) => `policyMembers_${index}`, - () => createRandomPolicyMember(), - ); - const personalDetails = createCollection( - (_, index) => `personalDetails_${index}`, - (index) => ({ - accountID: index, - }), - ); + test('500 policy members with errors and empty personal details', async () => { + const policyMembers = createCollection( + (_, index) => index, + () => ({ + ...createRandomPolicyMember(), + errors: {error: 'Error message'}, + }), + ); + const personalDetails = createCollection( + (_, index) => index, + (index) => ({ + accountID: index, + }), + ); - await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); + }); }); }); From 24dae43cf525041d46a502749203f7302cea9b5b Mon Sep 17 00:00:00 2001 From: Shridhar Goel <35566748+ShridharGoel@users.noreply.github.com> Date: Mon, 18 Mar 2024 16:36:46 +0530 Subject: [PATCH 15/16] Keep tests with full personal details --- tests/perf-test/PolicyUtils.perf-test.ts | 35 +----------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/tests/perf-test/PolicyUtils.perf-test.ts b/tests/perf-test/PolicyUtils.perf-test.ts index 5fffe7347b94..8c6bbc5e268c 100644 --- a/tests/perf-test/PolicyUtils.perf-test.ts +++ b/tests/perf-test/PolicyUtils.perf-test.ts @@ -7,7 +7,7 @@ import createRandomPolicyMember from '../utils/collections/policyMembers'; describe('PolicyUtils', () => { describe('getMemberAccountIDsForWorkspace', () => { - test('500 policy members and full personal details', async () => { + test('500 policy members with personal details', async () => { const policyMembers = createCollection( (_, index) => index, () => createRandomPolicyMember(), @@ -17,21 +17,6 @@ describe('PolicyUtils', () => { await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); - test('500 policy members and empty personal details', async () => { - const policyMembers = createCollection( - (_, index) => index, - () => createRandomPolicyMember(), - ); - const personalDetails = createCollection( - (_, index) => index, - (index) => ({ - accountID: index, - }), - ); - - await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); - }); - test('500 policy members with errors and full personal details', async () => { const policyMembers = createCollection( (_, index) => index, @@ -44,23 +29,5 @@ describe('PolicyUtils', () => { await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); - - test('500 policy members with errors and empty personal details', async () => { - const policyMembers = createCollection( - (_, index) => index, - () => ({ - ...createRandomPolicyMember(), - errors: {error: 'Error message'}, - }), - ); - const personalDetails = createCollection( - (_, index) => index, - (index) => ({ - accountID: index, - }), - ); - - await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); - }); }); }); From de6946b820c34c30b0379e5c977cbb0343198513 Mon Sep 17 00:00:00 2001 From: Shridhar Goel <35566748+ShridharGoel@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:13:45 +0530 Subject: [PATCH 16/16] Update tests/perf-test/PolicyUtils.perf-test.ts Co-authored-by: Pavlo Tsimura --- tests/perf-test/PolicyUtils.perf-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/perf-test/PolicyUtils.perf-test.ts b/tests/perf-test/PolicyUtils.perf-test.ts index 8c6bbc5e268c..98403b310f25 100644 --- a/tests/perf-test/PolicyUtils.perf-test.ts +++ b/tests/perf-test/PolicyUtils.perf-test.ts @@ -17,7 +17,7 @@ describe('PolicyUtils', () => { await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); }); - test('500 policy members with errors and full personal details', async () => { + test('500 policy members with errors and personal details', async () => { const policyMembers = createCollection( (_, index) => index, () => ({