performance-testing/tests/spike-test.js

36 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2023-09-26 10:52:17 +00:00
import http from 'k6/http';
2023-09-27 13:05:58 +00:00
import { sleep, check } from 'k6';
2023-09-26 10:52:17 +00:00
import { SharedArray } from 'k6/data';
2023-09-27 09:38:43 +00:00
var hostname = __ENV.HOSTNAME;
2023-09-27 08:51:36 +00:00
if (hostname == null) hostname = 'localhost:5157';
2023-09-26 10:52:17 +00:00
export const options = {
stages: [
2023-09-27 13:36:30 +00:00
{ duration: '30s', target: 2000 }, // ramp up
{ duration: '2m', target: 2000 }, // stable
{ duration: '30s', target: 0 }, // ramp-down to 0 users
2023-09-26 10:52:17 +00:00
],
};
const dates = new SharedArray('dates', function () {
var dates = [];
var currentDate = new Date();
var minDate = new Date();
minDate.setFullYear(currentDate.getFullYear() - 100);
for (var i = 0; i < 100; i++) {
var randomTime = Math.random() * (currentDate.getTime() - minDate.getTime());
var randomDate = new Date(minDate.getTime() + randomTime);
dates.push(randomDate.toISOString());
}
return dates;
});
export default () => {
const randomDate = dates[Math.floor(Math.random() * dates.length)];
2023-09-27 13:05:58 +00:00
const res = http.get(`http://${hostname}/age/${randomDate}`);
check(res, { '200': (r) => r.status === 200 });
2023-09-26 10:52:17 +00:00
sleep(1);
};