generated from pricelees/issue-pr-template
<!-- 제목 양식 --> <!-- [이슈번호] 작업 요약 (예시: [#10] Gitea 템플릿 생성) --> ## 📝 관련 이슈 및 PR **PR과 관련된 이슈 번호** - #64 ## ✨ 작업 내용 <!-- 어떤 작업을 했는지 알려주세요! --> - 기존의 결제 시도 이력 테이블 조회 & 검증 -> 예약 / 일정 조회 및 검증을 하나의 트랜잭션으로 통합 - 예약 / 일정 LOCK 조회를 가장 먼저 수행 -> 배치와의 충돌을 방지하기 위함 ## 🧪 테스트 <!-- 어떤 테스트를 생각했고 진행했는지 알려주세요! --> - 동일 조건에서 테스트했을 때 P95 응답 시간 749 -> 327ms로 50% 가량 개선 확인 - 커넥션 대기로 길어진 최대 API 응답 시간 7.70 -> 2.88초로 대폭 감소 ## 📚 참고 자료 및 기타 <!-- 참고한 자료, 또는 논의할 사항이 있다면 알려주세요! --> Reviewed-on: #65 Co-authored-by: pricelees <priceelees@gmail.com> Co-committed-by: pricelees <priceelees@gmail.com>
92 lines
2.4 KiB
JavaScript
92 lines
2.4 KiB
JavaScript
import http from 'k6/http';
|
|
|
|
export const BASE_URL = __ENV.BASE_URL || 'http://localhost:8080';
|
|
|
|
export function generateRandomBase64String(length) {
|
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
let result = '';
|
|
for (let i = 0; i < length; i++) {
|
|
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export function parseIdToString(response) {
|
|
try {
|
|
const safeJsonString = response.body.replace(/"(\w*Id|id)"\s*:\s*(\d{16,})/g, '"$1":"$2"');
|
|
return JSON.parse(safeJsonString);
|
|
} catch (e) {
|
|
console.error(`JSON parsing failed for VU ${__VU}: ${e}`);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function maxIterations() {
|
|
const maxIterationsRes = http.get(`${BASE_URL}/tests/max-iterations`)
|
|
if (maxIterationsRes.status !== 200) {
|
|
throw new Error('max-iterations 조회 실패')
|
|
}
|
|
|
|
return maxIterationsRes.json('count')
|
|
}
|
|
|
|
export function fetchUsers() {
|
|
const userCount = Math.round(maxIterations() * 0.5)
|
|
const userAccountRes = http.get(`http://localhost:8080/tests/users?count=${userCount}`)
|
|
|
|
if (userAccountRes.status !== 200) {
|
|
throw new Error('users 조회 실패')
|
|
}
|
|
|
|
return userAccountRes.json('results')
|
|
}
|
|
|
|
export function fetchStores() {
|
|
const storeIdListRes = http.get(`http://localhost:8080/tests/stores`)
|
|
|
|
if (storeIdListRes.status !== 200) {
|
|
throw new Error('stores 조회 실패')
|
|
}
|
|
|
|
return parseIdToString(storeIdListRes).results
|
|
}
|
|
|
|
export function login(account, password, principalType) {
|
|
const loginPayload = JSON.stringify({
|
|
account: account,
|
|
password: password,
|
|
principalType: principalType
|
|
})
|
|
const params = { headers: { 'Content-Type': 'application/json' } }
|
|
|
|
const loginRes = http.post(`${BASE_URL}/auth/login`, loginPayload, params)
|
|
|
|
if (loginRes.status !== 200) {
|
|
throw new Error(`로그인 실패: ${__VU}`)
|
|
}
|
|
|
|
const body = parseIdToString(loginRes).data
|
|
if (principalType === 'ADMIN') {
|
|
return {
|
|
storeId: body.storeId,
|
|
accessToken: body.accessToken
|
|
}
|
|
} else {
|
|
return {
|
|
accessToken: body.accessToken
|
|
}
|
|
}
|
|
}
|
|
|
|
export function getHeaders(token) {
|
|
const headers = {
|
|
'Content-Type': 'application/json',
|
|
};
|
|
|
|
if (token) {
|
|
headers['Authorization'] = `Bearer ${token}`;
|
|
}
|
|
|
|
return { headers: headers };
|
|
}
|