-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassessment.js
98 lines (95 loc) · 2.85 KB
/
assessment.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
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
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 virtualUsers = 15;
let numberOfIterations = 0;
const data = new SharedArray("assessment_dataset", function () {
const payloads = [];
function randomIntFromInterval(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
const csaAssessmentIds = JSON.parse(open("./prepared_csa_ids.json"));
const { studentIds, questionIds } = configurations[__ENV.ENVIRONMENT_NAME];
const today = new Date();
const epochDate = Math.floor(today.getTime() / 1000);
for (let id = 1; id <= csaAssessmentIds.length; id++) {
const { assessmentId, csaId, classId, subjectId } =
csaAssessmentIds[id - 1];
for (const questionId of questionIds) {
const assessmentSubmitPayload = {
csaId: csaId,
classId: classId,
subjectId,
assessmentId: assessmentId,
status: "ACTIVE",
starts: epochDate,
ends: epochDate,
assessmentResponsePayloads: studentIds.map((studentId) => ({
assessmentResponse: {
assessmentId: assessmentId,
csaId: csaId,
studentId: studentId,
createdAt: epochDate,
updatedBy: 1,
updatedByTeacher: 1,
},
assessmentResponseDetails: [
{
csaId,
questionId,
response: String(randomIntFromInterval(1, 6)),
createdAt: epochDate,
updatedBy: 1,
updatedByTeacher: 1,
},
],
})),
};
const payload = JSON.stringify({
payload: assessmentSubmitPayload,
});
payloads.push(payload);
}
}
const numberOfCalls =
csaAssessmentIds.length *
configurations[__ENV.ENVIRONMENT_NAME].questionIds.length;
numberOfIterations = Math.round(numberOfCalls / virtualUsers);
console.log(
payloads.length,
"**** Pay load Length*******",
numberOfIterations,
virtualUsers
);
return payloads;
});
export const options = {
scenarios: {
stress_test: {
executor: "per-vu-iterations",
vus: virtualUsers,
iterations: numberOfIterations,
maxDuration: "30m",
},
},
};
export default async function () {
const payload = data[exec.scenario.iterationInTest];
const { api_url } = configurations[__ENV.ENVIRONMENT_NAME];
const url = api_url + "/assessments/responses/submit";
const params = {
headers: {
"Content-Type": "application/json",
},
tags: { name: "SubmitAssessments" },
};
const res = http.post(url, payload, params);
check(res, {
"is status 200": (r) => r.status === 200,
"is success": (r) =>
r.body && res.json().submitManyAssessmentResponses.success === true,
});
sleep(1);
}