-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[NoQA] Add performance tests for getMemberAccountIDsForWorkspace #38271
Conversation
@paultsimura 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] |
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`, | ||
}, | ||
]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reuse the existing createPersonalDetails
function:
App/tests/utils/collections/personalDetails.ts
Lines 4 to 12 in 3cbb309
export default function createPersonalDetails(index: number): PersonalDetails { | |
return { | |
accountID: index, | |
avatar: randAvatar(), | |
displayName: randWord(), | |
lastName: randWord(), | |
login: randEmail(), | |
}; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
|
||
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: {}}])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use createCollection
:
App/tests/utils/collections/createCollection.ts
Lines 1 to 11 in 3cbb309
export default function createCollection<T>(createKey: (item: T, index: number) => string | number, createItem: (index: number) => T, length = 500): Record<string, T> { | |
const map: Record<string, T> = {}; | |
for (let i = 0; i < length; i++) { | |
const item = createItem(i); | |
const itemKey = createKey(item, i); | |
map[itemKey] = item; | |
} | |
return map; | |
} |
Also, create a separate util function createRandomPolicyMember
similar to createRandomPolicy
.
Read more here: https://github.com/Expensify/App/blob/6cdf088114314447c546467025d465568ef8f690/tests/README.md#mocking-collections--collection-items
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't commit the createRandomPolicyMember
util.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it.
Ok, now that the code looks good, let's look into the function you're writing tests for: Lines 124 to 143 in fecbd84
It uses mapping by the keys of Therefore, while building the mock data, do not use the custom key builders like |
Also, please restructure the test file in the following way: describe('PolicyUtils', () => {
describe('getMemberAccountIDsForWorkspace', () => {
test('500 policy members and full personal details'
...
test('500 policy members and empty personal details'
...
test('500 policy members with errors and full personal details'
...
test('500 policy members with errors and empty personal details'
... |
@paultsimura Updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@OlimpiaZurek could you please give this PR a second look? 🙏 |
Reviewer Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeiOS: NativeiOS: mWeb SafariMacOS: Chrome / SafariMacOS: Desktop |
@ShridharGoel The code looks good, but I'm not sure if all test scenarios are needed here. The purpose of these tests is to measure performance based on large amounts of data and catch possible regressions. Therefore, in my opinion, scenarios where the Additionally, we must take into account the execution time of these tests on CI, and each additional test increases this time. cc: @paultsimura |
Thank you, that makes sense👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with a tiny change – no need to re-request approval after the commit. Thanks ✔️
Co-authored-by: Pavlo Tsimura <[email protected]>
@OlimpiaZurek @mountiny Can you also have a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OlimpiaZurek do you want to review?
test('500 policy members with personal details', async () => { | ||
const policyMembers = createCollection<PolicyMember>( | ||
(_, index) => index, | ||
() => createRandomPolicyMember(), | ||
); | ||
const personalDetails = createCollection<PersonalDetails>((_, index) => index, createPersonalDetails); | ||
|
||
await measureFunction(() => getMemberAccountIDsForWorkspace(policyMembers, personalDetails)); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit weary on including both of these tests since if the member has any error they will not be returned.
Not a big deal, the function is not that complex so we could include both cases I think
🚀 Deployed to staging by https://github.com/mountiny in version: 1.4.54-0 🚀
|
🚀 Deployed to production by https://github.com/AndrewGable in version: 1.4.54-4 🚀
|
Details
Add performance tests for getMemberAccountIDsForWorkspace
Fixed Issues
$ #38167
PROPOSAL: #38167 (comment)
Tests
These are new performance tests, does not need manual testing.
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop