-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_test.js
More file actions
113 lines (95 loc) · 2.85 KB
/
load_test.js
File metadata and controls
113 lines (95 loc) · 2.85 KB
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
import http from "k6/http";
import { sleep, check } from "k6";
const BASE_URL = 'https://telegrammy.tech/api/v1';
export const options = {
stages: [
{ duration: "5s", target: 500 },
{ duration: "1m", target: 500 },
{ duration: "5s", target: 0 },
],
thresholds: {
http_req_duration: ["p(80)<1000"],
},
};
function generateRandomString(length) {
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
}
function generateRandomPhone() {
return '01' + Math.floor(Math.random() * 1000000000).toString().padStart(9, '0');
}
function generateVerificationCode() {
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789#@$%';
let code = '';
for (let i = 0; i < 12; i++) {
code += characters.charAt(Math.floor(Math.random() * characters.length));
}
return code;
}
function generateRegistrationPayload() {
const timestamp = new Date().getTime();
const username = `${generateRandomString(5)}_${timestamp}`;
const email = `${username}@example.com`;
const password = generateRandomString(12);
return {
username: username,
email: email,
password: password,
passwordConfirm: password,
phone: generateRandomPhone()
};
}
function generateVerificationPayload(email = null) {
return {
email: email || `${generateRandomString(8)}@example.com`,
verificationCode: generateVerificationCode()
};
}
function generateLoginPayload() {
const timestamp = new Date().getTime();
return {
"UUID": `${generateRandomString(5)}_${timestamp}@example.com`,
"password": generateRandomPhone()
}
}
export default () => {
const params = {
headers: {
'Content-Type': 'application/json',
},
};
const registrationPayload = generateRegistrationPayload();
const registrationRes = http.post(
`${BASE_URL}/auth/register`,
JSON.stringify(registrationPayload),
params
);
check(registrationRes, {
'registration status is 200': (r) => r.status === 201
});
sleep(1);
const verificationPayload = generateVerificationPayload(registrationPayload.email);
const verificationRes = http.post(
`${BASE_URL}/auth/verify`,
JSON.stringify(verificationPayload),
params
);
check(verificationRes, {
'verification status is 400': (r) => r.status === 400
});
sleep(1);
const loginPayload = generateLoginPayload();
const loginRes = http.post(
`${BASE_URL}/auth/login`,
JSON.stringify(loginPayload),
params
)
check(loginRes, {
'Login status is 401': (r) => r.status === 401
});
sleep(1);
};