diff --git a/test-scripts/create-reservation-scripts.js b/test-scripts/create-reservation-scripts.js index df99e730..4f33b6c1 100644 --- a/test-scripts/create-reservation-scripts.js +++ b/test-scripts/create-reservation-scripts.js @@ -95,42 +95,46 @@ export default function (data) { let availableScheduleId, selectedThemeId, selectedThemeInfo, reservationId, totalAmount group(`매장=${storeId}, 날짜=${targetDate}의 일정 조회`, function () { - const res = http.get(`${BASE_URL}/stores/${storeId}/schedules?date=${targetDate}`) - if (check(res, { '일정 조회 성공': (r) => r.status === 200 })) { - sleep(20) - let schedules = parseIdToString(res).data.schedules + let searchTrial = 0 + let schedules - if (!schedules || schedules.length === 0) { - console.log("일정 없음. 1회 재시도") - const storeId = randomItem(stores).storeId - const targetDate = randomDayBetween(1, 4) - const res = http.get(`${BASE_URL}/stores/${storeId}/schedules?date=${targetDate}`) - if (check(res, { '일정 조회 성공': (r) => r.status === 200 })) { - schedules = parseIdToString(res).data.schedules - } + while (searchTrial < 5) { + const res = http.get(`${BASE_URL}/stores/${storeId}/schedules?date=${targetDate}`) + const result = check(res, {'일정 조회 성공': (r) => r.status === 200}) + if (result !== true) { + continue } - + schedules = parseIdToString(res).data.schedules if (schedules && schedules.length > 0) { - group(`일부 테마는 상세 조회`, function () { - const themesByStoreAndDate = schedules.map(s => s.theme) - if (!themesByStoreAndDate && themesByStoreAndDate.length <= 0) { - return - } - const randomThemesForFetchDetail = extractRandomThemeForFetchDetail(themesByStoreAndDate) - - randomThemesForFetchDetail.forEach(id => { - http.get(`${BASE_URL}/themes/${id}`) - sleep(10) - }) - }) - - const availableSchedules = schedules.filter((s) => s.schedule.status === 'AVAILABLE') - if (availableSchedules.length > 0) { - const availableSchedule = randomItem(availableSchedules) - availableScheduleId = availableSchedule.schedule.id - selectedThemeId = availableSchedule.theme.id - } + break } + searchTrial++ + sleep(10) + } + + if (schedules.length <= 0) { + console.log(`5회 시도에도 일정 조회 실패`) + return; + } + + group(`일부 테마는 상세 조회`, function () { + const themesByStoreAndDate = schedules.map(s => s.theme) + if (!themesByStoreAndDate && themesByStoreAndDate.length <= 0) { + return + } + const randomThemesForFetchDetail = extractRandomThemeForFetchDetail(themesByStoreAndDate) + + randomThemesForFetchDetail.forEach(id => { + http.get(`${BASE_URL}/themes/${id}`) + sleep(10) + }) + }) + + const availableSchedules = schedules.filter((s) => s.schedule.status === 'AVAILABLE') + if (availableSchedules.length > 0) { + const availableSchedule = randomItem(availableSchedules) + availableScheduleId = availableSchedule.schedule.id + selectedThemeId = availableSchedule.theme.id } }) @@ -139,33 +143,33 @@ export default function (data) { } let isScheduleHeld = false - group(`일정 Holding 및 테마 정보 조회 -> 예약 과정중 첫 페이지의 작업 완료`, function () { const holdRes = http.post(`${BASE_URL}/schedules/${availableScheduleId}/hold`, null, getHeaders(accessToken)) + const body = JSON.parse(holdRes) - if (check(holdRes, { '일정 점유 성공': (r) => r.status === 200 })) { + if (check(holdRes, {'일정 점유 성공': (r) => r.status === 200})) { const themeInfoRes = http.get(`${BASE_URL}/themes/${selectedThemeId}`) - if (themeInfoRes.status !== 200) { - throw new Error("테마 상세 조회 실패") - } selectedThemeInfo = parseIdToString(themeInfoRes).data isScheduleHeld = true + } else { + const errorCode = body.code + const errorMessage = body.message + + console.log(`일정 점유 실패: code=${errorCode}, message=${errorMessage}`) } }) - if (!isScheduleHeld) { - console.log("일정 점유 실패") + if (!isScheduleHeld || !selectedThemeInfo) { return } let isPendingReservationCreated = false - group(`예약 정보 입력 페이지`, function () { let userName, userContact group(`회원 연락처 조회`, function () { const userContactRes = http.get(`${BASE_URL}/users/contact`, getHeaders(accessToken)) - if (!check(userContactRes, { '회원 연락처 조회 성공': (r) => r.status === 200 })) { + if (!check(userContactRes, {'회원 연락처 조회 성공': (r) => r.status === 200})) { throw new Error("회원 연락처 조회 과정에서 예외 발생") } @@ -210,14 +214,12 @@ export default function (data) { }) if (!isPendingReservationCreated) { - console.log("회원의 예약 정보 입력 중 페이지 이탈") return; } group(`결제 및 예약 확정`, function () { // 20%의 유저는 결제 화면에서 나감 => 배치의 자동 만료 처리 테스트 if (Math.random() <= 0.2) { - console.log("결제 페이지에서의 이탈") return } @@ -236,7 +238,7 @@ export default function (data) { sleep(30) const confirmOrderRes = http.post(`${BASE_URL}/orders/${reservationId}/confirm`, payload, getHeaders(accessToken)) - if (check(confirmOrderRes, { '예약 확정 성공': (r) => r.status === 200 })) { + if (check(confirmOrderRes, {'예약 확정 성공': (r) => r.status === 200})) { isConfirmed = true break } @@ -253,7 +255,7 @@ export default function (data) { sleep(10) 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 }