From a16144a4009de12a5aee118ec19a59b2376ac1c0 Mon Sep 17 00:00:00 2001 From: pricelees Date: Sat, 11 Oct 2025 12:05:40 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20k6=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test-scripts/create-reservation-scripts.js | 31 +++++++++++++++++----- test-scripts/create-schedule-scripts.js | 10 +++---- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/test-scripts/create-reservation-scripts.js b/test-scripts/create-reservation-scripts.js index 4be7035c..cd6a7e7f 100644 --- a/test-scripts/create-reservation-scripts.js +++ b/test-scripts/create-reservation-scripts.js @@ -14,9 +14,19 @@ import http from 'k6/http'; export const options = { scenarios: { user_reservation: { - executor: 'constant-vus', - vus: 15, - duration: '15m' + executor: 'ramping-vus', + startVUs: 0, + 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}`) if (check(res, { '일정 조회 성공': (r) => r.status === 200 })) { sleep(20) - const schedules = parseIdToString(res).data.schedules - if (schedules) { + let schedules = parseIdToString(res).data.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 () { const themesByStoreAndDate = schedules.map(s => s.theme) if (!themesByStoreAndDate && themesByStoreAndDate.length <= 0) { @@ -112,7 +131,6 @@ export default function (data) { }) if (!availableScheduleId) { - console.log("이용 가능한 일정 없음.") return; } @@ -224,6 +242,7 @@ export default function (data) { sleep(10) const temporalConfirmRes = http.post(`${BASE_URL}/reservations/${reservationId}/confirm`) if (check(temporalConfirmRes, { '임시 예약 확정 성공': (r) => r.status === 200})) { + console.log("예약 확정 성공") return } throw new Error('임시 예약 확정 실패') diff --git a/test-scripts/create-schedule-scripts.js b/test-scripts/create-schedule-scripts.js index 28f26774..9d533cf3 100644 --- a/test-scripts/create-schedule-scripts.js +++ b/test-scripts/create-schedule-scripts.js @@ -1,12 +1,10 @@ import http from 'k6/http'; import {check, sleep} from 'k6'; 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'; -const BASE_URL = __ENV.BASE_URL || 'http://localhost:8080'; - const TOTAL_ITERATIONS = 85212; export const options = { @@ -46,7 +44,7 @@ export function setup() { console.error(`[Setup] 로그인 실패: ${account.account}`); continue; } - const { storeId, accessToken } = loginResult; + const {storeId, accessToken} = loginResult; // 5 ~ ${themes.size} 인 random 숫자 생성 const selectedThemes = selectRandomThemes(themes, randomIntBetween(5, themes.length)); @@ -68,10 +66,10 @@ export function setup() { console.log(`총 생성할 스케줄 수(iterations): ${tasks.length}`); - return { tasks }; + return {tasks}; } -export default function(data) { +export default function (data) { // 👈 3. 현재 반복 횟수가 준비된 작업 수를 초과하는지 확인 const taskIndex = exec.scenario.iterationInTest;