-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.js
72 lines (68 loc) · 1.96 KB
/
load.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
import http from 'k6/http';
import { check } from 'k6';
import { randomString } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
export const options = {
thresholds: {
http_req_failed: [{ threshold: 'rate<0.01', abortOnFail: true }],
http_req_duration: [{ threshold: 'p(95)<250', abortOnFail: true }],
checks: ['rate>0.9'],
},
scenarios: {
reads: {
executor: 'ramping-arrival-rate',
preAllocatedVUs: 50,
exec: 'reads',
stages: [
{ duration: '5m', target: 500 },
{ duration: '15m', target: 500 },
{ duration: '5m', target: 0 },
],
},
writes: {
executor: 'constant-arrival-rate',
duration: '25m',
rate: 1,
timeUnit: '1s',
preAllocatedVUs: 1,
exec: 'writes',
},
},
};
export function reads() {
const url = `http://${__ENV.API_IP}/WeatherForecast`;
const params = {
headers: {
'Host': 'app.test',
'accept':'application/json',
},
};
check(http.get(url, params), {
'status 200': (r) => r.status === 200,
'correct api response': (r) =>
r.body.includes('temperature'),
});
}
export function writes() {
const randomSummary = randomString(5);
const randomTemp = randomIntBetween(0, 40);
const url = `http://${__ENV.API_IP}/Forecast/3`;
const data = { "id": 3, "cityId": 3, "dateTime": 10, "temperature": `${randomTemp}`, "summary": `${randomSummary}` }
const params = {
headers: {
'Host': 'app.test',
'Content-Type': 'application/json',
},
};
check(http.put(url, JSON.stringify(data), params), {
'status 200': (r) => r.status === 200,
});
}
export function handleSummary(data) {
console.log('Finished executing performance tests');
return {
'stdout': textSummary(data, { indent: ' ', enableColors: false }),
'summary.txt': textSummary(data, { indent: ' ', enableColors: false }),
"result.html": htmlReport(data),
};
}