-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworkload.js
46 lines (40 loc) · 1.16 KB
/
workload.js
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
/**
* Creates a workload from a scenario
*
* @param { Scenario } scenario the chosen scenario.
* @returns returns a workload model
*/
export function createWorkloadFromScenario (scenario, mapPageToFun = (p) => null, mapEventToFun = (p) => null) {
const states = [];
scenario.scenarioStates.forEach(scenarioState => {
const { events, page, targets, thinkTime } = scenarioState;
const pageFun = mapPageToFun(page);
if (!pageFun) {
throw Error(`No function found for page: ${page}`);
}
if (events) {
events.map(e => { e.action = mapEventToFun(e.name); });
}
states.push({
name: page,
targets: targets,
action: function () {
pageFun(thinkTime); // Visit page action
},
events
});
});
// Add the abandon state.
const abandonFun = mapPageToFun('abandon');
states.push({
name: 'abandon',
targets: [],
action: abandonFun
});
// Return the workload model
return {
initial: states[0].name,
abandon: 'abandon',
states: states
};
}