-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
60 lines (55 loc) · 1.37 KB
/
test.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
import http from 'k6/http';
import {check} from 'k6';
import { Rate } from 'k6/metrics';
const failures = new Rate('failed requests');
export const options = {
ext:{
loadimpact:{
projectID: '<your project id in k6 cloud>',
name: 'K6 demo',
},
},
scenarios: {
test: {
executor: "ramping-vus",
startVUs: 1,
stages: [
{
duration: "30s",
target: 5, // normal load
},
{
duration: "10s",
target: 20, //spike to 15 vus
},
{
duration: "10s",
target: 40,
},
{
duration: "10s",
target: 50
}
]
},
},
thresholds: {
failed_requests: ['rate<=0'],
http_req_duration: ['p(95)<100', 'p(99)<500'],
}
}
export default function () {
const result = http.get("http://test-api.k6.io");
checkResult(result, "default", 200);
failures.add(result.status != 200);
}
function checkResult(res, tag, resCode){
check(
res,
{
['status' + tag + ' is ' + resCode + ' (Ok)']: (r) =>
r.status === resCode,
},
{ my_tag: tag }
);
}