[#58] K6 성능 테스트 도입 #59

Merged
pricelees merged 8 commits from feat/#58 into main 2025-10-11 07:38:27 +00:00
2 changed files with 29 additions and 12 deletions
Showing only changes of commit a16144a400 - Show all commits

View File

@ -14,9 +14,19 @@ import http from 'k6/http';
export const options = { export const options = {
scenarios: { scenarios: {
user_reservation: { user_reservation: {
executor: 'constant-vus', executor: 'ramping-vus',
vus: 15, startVUs: 0,
duration: '15m' stages: [
{ duration: '1m', target: 5 },
{ duration: '1m', target: 10 },
{ duration: '1m', target: 15 },
{ duration: '1m', target: 20 },
{ duration: '1m', target: 25 },
{ duration: '1m', target: 30 },
{ duration: '1m', target: 35 },
{ duration: '1m', target: 40 },
{ duration: '1m', target: 0 },
]
} }
}, },
@ -86,8 +96,17 @@ export default function (data) {
const res = http.get(`${BASE_URL}/stores/${storeId}/schedules?date=${targetDate}`) const res = http.get(`${BASE_URL}/stores/${storeId}/schedules?date=${targetDate}`)
if (check(res, { '일정 조회 성공': (r) => r.status === 200 })) { if (check(res, { '일정 조회 성공': (r) => r.status === 200 })) {
sleep(20) sleep(20)
const schedules = parseIdToString(res).data.schedules let schedules = parseIdToString(res).data.schedules
if (schedules) {
if (!schedules || schedules.length === 0) {
console.log("일정 없음. 1회 재시도")
const storeId = randomItem(stores).storeId
const targetDate = randomDayBetween(0, 6)
const res = http.get(`${BASE_URL}/stores/${storeId}/schedules?date=${targetDate}`)
schedules = parseIdToString(res).data.schedules
}
if (schedules && schedules.length > 0) {
group(`일부 테마는 상세 조회`, function () { group(`일부 테마는 상세 조회`, function () {
const themesByStoreAndDate = schedules.map(s => s.theme) const themesByStoreAndDate = schedules.map(s => s.theme)
if (!themesByStoreAndDate && themesByStoreAndDate.length <= 0) { if (!themesByStoreAndDate && themesByStoreAndDate.length <= 0) {
@ -112,7 +131,6 @@ export default function (data) {
}) })
if (!availableScheduleId) { if (!availableScheduleId) {
console.log("이용 가능한 일정 없음.")
return; return;
} }
@ -224,6 +242,7 @@ export default function (data) {
sleep(10) sleep(10)
const temporalConfirmRes = http.post(`${BASE_URL}/reservations/${reservationId}/confirm`) const temporalConfirmRes = http.post(`${BASE_URL}/reservations/${reservationId}/confirm`)
if (check(temporalConfirmRes, { '임시 예약 확정 성공': (r) => r.status === 200})) { if (check(temporalConfirmRes, { '임시 예약 확정 성공': (r) => r.status === 200})) {
console.log("예약 확정 성공")
return return
} }
throw new Error('임시 예약 확정 실패') throw new Error('임시 예약 확정 실패')

View File

@ -1,12 +1,10 @@
import http from 'k6/http'; import http from 'k6/http';
import {check, sleep} from 'k6'; import {check, sleep} from 'k6';
import exec from 'k6/execution'; import exec from 'k6/execution';
import {getHeaders, login, parseIdToString} from "./common.js"; import {BASE_URL, getHeaders, login, parseIdToString} from "./common.js";
import {randomIntBetween} 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';
const BASE_URL = __ENV.BASE_URL || 'http://localhost:8080';
const TOTAL_ITERATIONS = 85212; const TOTAL_ITERATIONS = 85212;
export const options = { export const options = {
@ -46,7 +44,7 @@ export function setup() {
console.error(`[Setup] 로그인 실패: ${account.account}`); console.error(`[Setup] 로그인 실패: ${account.account}`);
continue; continue;
} }
const { storeId, accessToken } = loginResult; const {storeId, accessToken} = loginResult;
// 5 ~ ${themes.size} 인 random 숫자 생성 // 5 ~ ${themes.size} 인 random 숫자 생성
const selectedThemes = selectRandomThemes(themes, randomIntBetween(5, themes.length)); const selectedThemes = selectRandomThemes(themes, randomIntBetween(5, themes.length));
@ -68,10 +66,10 @@ export function setup() {
console.log(`총 생성할 스케줄 수(iterations): ${tasks.length}`); console.log(`총 생성할 스케줄 수(iterations): ${tasks.length}`);
return { tasks }; return {tasks};
} }
export default function(data) { export default function (data) {
// 👈 3. 현재 반복 횟수가 준비된 작업 수를 초과하는지 확인 // 👈 3. 현재 반복 횟수가 준비된 작업 수를 초과하는지 확인
const taskIndex = exec.scenario.iterationInTest; const taskIndex = exec.scenario.iterationInTest;