Chore/#101 vacancy subscribe load test - #102
Conversation
3-Phase 구조로 SADD/SMEMBERS/TTL 각각 측정 - PHASE 1: POST /api/v1/vacancy 100회 호출로 SADD 부하 - PHASE 2: k6/experimental/redis 로 SMEMBERS 응답시간 측정 - PHASE 3: TTL/EXISTS 로 키 자동 삭제 확인
There was a problem hiding this comment.
Code Review
This pull request introduces a k6 load test script (11-vacancy-test.js) to measure Redis SADD/SMEMBERS response times and verify TTL expiration, along with a Spring Boot utility (VacancyLoadTestTokenGenerator.java) to generate JWT tokens for the test. The review feedback suggests using the @Commit annotation in the token generator to eliminate the need for manual code changes during testing, updating the k6 script's documentation to reflect this simplification, and conditionally initializing the Redis client in the k6 script to avoid unnecessary connection attempts during the subscription phase.
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.transaction.annotation.Transactional; |
There was a problem hiding this comment.
테스트가 완료된 후 데이터를 데이터베이스에 커밋하기 위해 @Commit 어노테이션을 사용할 수 있습니다. 이렇게 하면 사용자가 테스트 실행 시 매번 @Transactional을 수동으로 주석 처리하고 다시 원복해야 하는 번거로움과 실수를 방지할 수 있습니다.
org.springframework.test.annotation.Commit을 임포트하여 적용해 주세요.
| import org.springframework.transaction.annotation.Transactional; | |
| import org.springframework.test.annotation.Commit; | |
| import org.springframework.transaction.annotation.Transactional; |
| @Test | ||
| @Transactional | ||
| void generateTokens() throws IOException { |
| * 1. 백엔드 코드 임시 수정 (테스트 끝나면 반드시 원복!) | ||
| * 파일: backend/src/test/java/com/catchtable/loadtest/VacancyLoadTestTokenGenerator.java | ||
| * generateTokens() 위의 `@Transactional` 어노테이션을 주석 처리한다. | ||
| * ( @Transactional 이 살아있으면 시드 유저가 롤백되어 k6 요청에서 USER_NOT_FOUND 발생 ) | ||
| * | ||
| * 2. 시드 유저 100명 + 토큰 100개 생성 (backend 디렉토리에서) |
There was a problem hiding this comment.
VacancyLoadTestTokenGenerator에 @Commit 어노테이션을 적용하면 테스트 실행 시 코드를 임시로 수정하고 원복할 필요가 없어집니다. 따라서 이 가이드 부분을 제거하고 단계를 단순화할 수 있습니다.
| * 1. 백엔드 코드 임시 수정 (테스트 끝나면 반드시 원복!) | |
| * 파일: backend/src/test/java/com/catchtable/loadtest/VacancyLoadTestTokenGenerator.java | |
| * generateTokens() 위의 `@Transactional` 어노테이션을 주석 처리한다. | |
| * ( @Transactional 이 살아있으면 시드 유저가 롤백되어 k6 요청에서 USER_NOT_FOUND 발생 ) | |
| * | |
| * 2. 시드 유저 100명 + 토큰 100개 생성 (backend 디렉토리에서) | |
| * 1. 시드 유저 100명 + 토큰 100개 생성 (backend 디렉토리에서) |
| * - VacancyLoadTestTokenGenerator.java 의 `@Transactional` 주석 원복. | ||
| * - 시드 데이터 정리: |
| const auth = REDIS_PASSWORD ? `:${encodeURIComponent(REDIS_PASSWORD)}@` : ''; | ||
| return `redis://${auth}${REDIS_ADDR}`; | ||
| })(); | ||
| const redisClient = new redis.Client(REDIS_URL); |
There was a problem hiding this comment.
PHASE가 subscribe일 때는 Redis를 사용하지 않으므로, Redis 클라이언트를 무조건 생성하기보다는 해당 페이즈가 아닐 때만 조건부로 생성하는 것이 좋습니다. 이렇게 하면 Redis 연결이 불가능한 환경에서 subscribe 부하 테스트만 실행할 때 발생할 수 있는 불필요한 연결 시도나 오류를 방지할 수 있습니다.
| const redisClient = new redis.Client(REDIS_URL); | |
| const redisClient = PHASE !== 'subscribe' ? new redis.Client(REDIS_URL) : null; |
📢 기능 설명
필요시 실행결과 스크린샷 첨부
연결된 issue
연결된 issue를 자동을 닫기 위해 아래 {이슈넘버}를 입력해주세요.
close #{이슈넘버}
✅ 체크리스트