51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
import http from 'k6/http';
|
|
import { check, sleep } from 'k6';
|
|
|
|
const BASE_URL = __ENV.BASE_URL || 'http://app:3000';
|
|
const seed = JSON.parse(open('./seed-data.json'));
|
|
|
|
export const options = {
|
|
stages: [
|
|
{ duration: '15s', target: 1 },
|
|
{ duration: '20s', target: 3 },
|
|
{ duration: '20s', target: 5 },
|
|
{ duration: '10s', target: 0 },
|
|
],
|
|
thresholds: {
|
|
http_req_failed: ['rate<0.01'],
|
|
http_req_duration: ['p(95)<500'],
|
|
checks: ['rate>0.99'],
|
|
},
|
|
};
|
|
|
|
export default function () {
|
|
const user = seed.users[(__VU + __ITER) % seed.users.length];
|
|
const session =
|
|
seed.sessions[(__VU + __ITER) % seed.sessions.length];
|
|
|
|
const requests = [
|
|
['users', `${BASE_URL}/users/`],
|
|
['teachers', `${BASE_URL}/teachers/`],
|
|
[
|
|
'available sessions',
|
|
`${BASE_URL}/sessions/available?dateTimestamp=${encodeURIComponent(session.dateTimestamp)}`,
|
|
],
|
|
[
|
|
'user session history',
|
|
`${BASE_URL}/sessions/${user.id}/sessions`,
|
|
],
|
|
];
|
|
|
|
for (const [name, url] of requests) {
|
|
const response = http.get(url);
|
|
|
|
check(response, {
|
|
[`${name}: HTTP 200`]: (r) => r.status === 200,
|
|
[`${name}: JSON response`]: (r) =>
|
|
r.headers['Content-Type']?.includes('application/json'),
|
|
});
|
|
}
|
|
|
|
sleep(1);
|
|
}
|