-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmock-test.js
executable file
·76 lines (64 loc) · 1.66 KB
/
smock-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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import http, { request } from "k6/http";
import { check, sleep } from "k6";
import { Trend, Rate } from "k6/metrics";
export let options = {
vus: 3,
duration: "1h",
thresholds: {
http_req_duration: ["p(95)<1000"],
},
};
const BASE_URL = __ENV.BASE_URL || "http://0.0.0.0:5000";
const SLEEP_DURATION = 0.1;
const APIS = {
dashboard: {
url: "/api/v2/dashboard",
method: "GET",
},
randomSearch: {
url: "/api/v2/search/random",
method: "POST",
},
getChild: {
url: "/api/v2/child/childId=1&confirm=2",
method: "GET",
},
userChildren: {
url: "/api/v2/user/children/userId=me",
method: "GET",
},
childNeeds: {
url: "/api/v2/child/childId=69/needs",
method: "GET",
},
};
Object.keys(APIS).map(function (api, index) {
APIS[api].params = {};
APIS[api].url = BASE_URL + APIS[api].url;
APIS[api].trend = new Trend(api);
APIS[api].errors = new Rate(api);
});
export default function () {
const loginUrl = BASE_URL + "/api/v2/auth/login?_lang=fa";
const loginResp = http.post(loginUrl, {
username: "rhonin",
password: 2,
isInstalled: 1,
});
const token = loginResp.json().accessToken;
Object.keys(APIS).map(function (api, index) {
if (APIS[api].params.headers) {
APIS[api].params.headers.Authorization = token;
} else {
APIS[api].params.headers = { Authorization: token };
}
});
const responses = http.batch(APIS);
Object.keys(responses).map(function (api, index) {
check(responses[api], {
"status is 200": (r) => r.status === 200,
}) || APIS[api].errors.add(1);
APIS[api].trend.add(responses[api].timings.duration);
});
sleep(SLEEP_DURATION);
}