-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ReportActionsUtils.perf-test.ts
147 lines (125 loc) · 5.69 KB
/
ReportActionsUtils.perf-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import Onyx from 'react-native-onyx';
import {measureFunction} from 'reassure';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ReportActions} from '@src/types/onyx/ReportAction';
import type ReportAction from '@src/types/onyx/ReportAction';
import createCollection from '../utils/collections/createCollection';
import createRandomReportAction from '../utils/collections/reportActions';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
const getMockedReportActionsMap = (reportsLength = 10, actionsPerReportLength = 100) => {
const mockReportActions = Array.from({length: actionsPerReportLength}, (v, i) => {
const reportActionKey = i + 1;
const reportAction = createRandomReportAction(reportActionKey);
return {[reportActionKey]: reportAction};
});
const reportKeysMap = Array.from({length: reportsLength}, (v, i) => {
const key = i + 1;
return {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${key}`]: Object.assign({}, ...mockReportActions)};
});
return Object.assign({}, ...reportKeysMap) as Partial<ReportAction>;
};
const mockedReportActionsMap = getMockedReportActionsMap(2, 10000);
const reportActions = createCollection<ReportAction>(
(item) => `${item.reportActionID}`,
(index) => createRandomReportAction(index),
);
const reportId = '1';
describe('ReportActionsUtils', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
Onyx.multiSet({
...mockedReportActionsMap,
});
});
afterAll(() => {
Onyx.clear();
});
/**
* 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('[ReportActionsUtils] getLastVisibleAction on 10k reportActions', async () => {
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId));
});
test('[ReportActionsUtils] getLastVisibleAction on 10k reportActions with actionsToMerge', async () => {
const parentReportActionId = '1';
const fakeParentAction = reportActions[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: [],
},
} as unknown as ReportActions;
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId, actionsToMerge));
});
test('[ReportActionsUtils] getMostRecentIOURequestActionID on 10k ReportActions', async () => {
const reportActionsArray = ReportActionsUtils.getSortedReportActionsForDisplay(reportActions);
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getMostRecentIOURequestActionID(reportActionsArray));
});
test('[ReportActionsUtils] getLastVisibleMessage on 10k ReportActions', async () => {
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId));
});
test('[ReportActionsUtils] getLastVisibleMessage on 10k ReportActions with actionsToMerge', async () => {
const parentReportActionId = '1';
const fakeParentAction = reportActions[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: [],
},
} as unknown as ReportActions;
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId, actionsToMerge));
});
test('[ReportActionsUtils] getSortedReportActionsForDisplay on 10k ReportActions', async () => {
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getSortedReportActionsForDisplay(reportActions));
});
test('[ReportActionsUtils] getLastClosedReportAction on 10k ReportActions', async () => {
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getLastClosedReportAction(reportActions));
});
test('[ReportActionsUtils] getMostRecentReportActionLastModified', async () => {
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getMostRecentReportActionLastModified());
});
});