-
Notifications
You must be signed in to change notification settings - Fork 0
/
performance.js
61 lines (52 loc) · 1.33 KB
/
performance.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
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
scenarios: {
authorization: {
executor: 'ramping-vus',
exec: "startAuthorization",
startVUs: 0,
stages: [
{ duration: '1s', target: 25 },
{ duration: '10s', target: 0 }
]
},
users: {
executor: 'per-vu-iterations',
exec: "getUsers",
vus: 40,
iterations: 2,
startTime: '5s'
}
},
thresholds: {
http_req_duration: ['p(95) < 250', 'p(90) < 100'],
http_req_failed: ['rate<=0.05']
}
}
export function startAuthorization() {
const url = 'https://httpbin.org/post';
const payload = JSON.stringify({
login: "test",
password: "password"
})
const params = {
headers: {
'Content-Type': 'application/json'
}
}
const res = http.post(url, payload, params);
check(res, {
'status code is 200': (r) => r.status == 200,
'body include login': (r) => r.body.includes("test")
})
sleep(1)
}
export function getUsers() {
const res = http.get('https://jsonplaceholder.typicode.com/users')
check(res, {
'status code is 200': (r) => r.status == 200,
'body is includes': (r) => r.body.length > 0
})
sleep(1)
}