Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[#44]Feat: K6 테스트 코드 추가 #69

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions backend/load_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import http from 'k6/http';
import { check, sleep } from 'k6';

export let options = {
stages: [
{ duration: '3m', target: 25 }, // 먼저 3분 동안 VUser 1에서 25까지 서서히 올린다.
{ duration: '3m',target: 25 }, // Vuser 25에서 10분간 유지한다.
{ duration: '3m', target: 125 }, // 다시 3분간 25에서 125까지 서서히 올린다.
{ duration: '3m',target: 125 }, // 30분간 유지
{ duration: '3m', target: 0 }, // 3분 동안 Vuser 0으로 내려온다.
],
thresholds: {
http_req_duration: ['p(95)<138'], // 전체 요청의 95%가 138ms 안에 들어오면 성공
},
};

const BASE_URL = 'http://localhost:8000/api/pets';

export default function () {
// 사용자 ID를 2 또는 3으로 설정
const user_id = Math.random() < 0.5 ? 2 : 3;
const url = `${BASE_URL}/list/${user_id}/`;

// API 요청
const res = http.get(url);

// 응답 확인
check(res, {
'status is 200': (r) => r.status === 200,
'response has data': (r) => r.json().length > 0,
});

// 부하 테스트 간 지연
sleep(1);
}