-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattendance.js
65 lines (59 loc) · 1.74 KB
/
attendance.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import http from "k6/http";
import exec from "k6/execution";
import { check, sleep } from "k6";
import { SharedArray } from "k6/data";
import { configurations } from "./config.js";
const numberOfDates = 100;
const virtualUsers = 20;
const data = new SharedArray("attendance_dataset", function () {
const payloads = [];
const { studentIds } = configurations[__ENV.ENVIRONMENT_NAME];
for (let id = 1; id <= numberOfDates; id++) {
const today = new Date();
today.setDate(today.getDate() + id);
const epochDate = Math.floor(today.getTime() / 1000);
const payload = JSON.stringify({
payload: studentIds.map((studentId) => ({
sessionId: 1,
studentId: studentId,
ayId: 1,
date: epochDate,
attendance: "PRESENT",
})),
});
payloads.push(payload);
}
return payloads;
});
export const options = {
// A number specifying the number of VUs to run concurrently.
// vus: 1,
// A string specifying the total duration of the test run.
// duration: "1s",
scenarios: {
stress_test: {
executor: "per-vu-iterations",
vus: virtualUsers,
iterations: Math.round(numberOfDates / virtualUsers),
// maxDuration: "30s",
},
},
};
export default function () {
const payload = data[exec.scenario.iterationInTest];
const { api_url } = configurations[__ENV.ENVIRONMENT_NAME];
const url = api_url + "/attendances/submit";
const params = {
headers: {
"Content-Type": "application/json",
},
tags: { name: "SubmitAttendance" },
};
const res = http.post(url, payload, params);
check(res, {
"is status 200": (r) => r.status === 200,
"is success": (r) =>
r.body && res.json().submitManyAttendances.success === true,
});
sleep(1);
}