forked from grafana/quickpizza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01.basic.js
58 lines (49 loc) · 1.42 KB
/
01.basic.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
import http from "k6/http";
import {check, sleep} from "k6";
import {ServiceDisruptor} from "k6/x/disruptor";
const BASE_URL = __ENV.BASE_URL || "http://localhost:3333";
const scenarios = {
disrupt: {
executor: "shared-iterations",
iterations: 1,
exec: "disrupt",
},
load: {
executor: "constant-vus",
vus: 5,
duration: "30s",
startTime: "5s",
},
};
if (__ENV.DISABLE_DISRUPT) {
delete scenarios["disrupt"];
}
export const options = {
scenarios: scenarios,
};
export function disrupt(data) {
const disruptor = new ServiceDisruptor("quickpizza-catalog", "default");
const targets = disruptor.targets();
if (targets.length === 0) {
throw new Error("expected list to have one target");
}
disruptor.injectHTTPFaults({errorRate: 0.1, errorCode: 503}, "40s");
}
export default function () {
const restrictions = {
"maxCaloriesPerSlice": 500,
"mustBeVegetarian": false,
"excludedIngredients": ["pepperoni"],
"excludedTools": ["knife"],
"maxNumberOfToppings": 6,
"minNumberOfToppings": 2
}
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
headers: {
"Content-Type": "application/json",
"Authorization": "token abcdef0123456789",
},
});
check(res, {"status is 200": (res) => res.status === 200});
sleep(1);
}