generated from pricelees/issue-pr-template
<!-- 제목 양식 --> <!-- [이슈번호] 작업 요약 (예시: [#10] Gitea 템플릿 생성) --> ## 📝 관련 이슈 및 PR **PR과 관련된 이슈 번호** - #58 ## ✨ 작업 내용 <!-- 어떤 작업을 했는지 알려주세요! --> - K6 성능 테스트 스크립트 추가 및 배포 환경에서의 정상 동작 확인 - 정상 동작 과정 확인 중 발견된 slow-query 개선 => 커버링 인덱스를 생각했으나, 실제로 사용하지 않고 테이블 풀스캔을 하던 문제 ## 🧪 테스트 <!-- 어떤 테스트를 생각했고 진행했는지 알려주세요! --> - 스크립트는 크게 사용자가 예약할 수 있는 일정을 만드는 작업과 사용자가 예약하는 작업 두 가지로 구분 - 후자의 테스트는 40VU까지는 여유있게 처리 확인 => 다음 과정부터는 부하를 더 높여 진행할 예정 ## 📚 참고 자료 및 기타 <!-- 참고한 자료, 또는 논의할 사항이 있다면 알려주세요! --> Reviewed-on: #59 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() * 1.2)
|
|
const userAccountRes = http.get(`${BASE_URL}/tests/users?count=${userCount}`)
|
|
|
|
if (userAccountRes.status !== 200) {
|
|
throw new Error('users 조회 실패')
|
|
}
|
|
|
|
return userAccountRes.json('results')
|
|
}
|
|
|
|
export function fetchStores() {
|
|
const storeIdListRes = http.get(`${BASE_URL}/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 };
|
|
}
|