Repository navigation
bug: 테스트 픽스처 누수로 클래스 순서에 따라 테스트가 깨지는 문제 (#74) - #75
Merged
Merged
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (1)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
HumanDeleteApiTest(#64에서 추가)가 공유 테스트 DB에 남긴 픽스처 때문에 클래스 실행 순서가 바뀌면IssuanceHistoryApiTest2개가 깨지던 문제를 고친다.Closes #74
왜 지금 CI는 초록인가
테스트 DB가 테스트 JVM 전체에서 하나이고(
jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1), JUnit 기본 클래스 순서가 우연히IssuanceHistoryApiTest→HumanDeleteApiTest라서 통과하고 있었다. 순서만 뒤집으면 바로 깨진다.원인
발급_건이_있으면_409를_주고_인적사항과_발급_건이_그대로_남는다가 남기는 발급 건의issuedAt이2026-09-01로,IssuanceHistoryApiTest픽스처(2026-08-20,2026-08-25)보다 최신이다. 발급 이력이order by issuedAt desc이므로 이 행이 1페이지 맨 앞을 차지하고, "최신순 첫 항목" 단언이 깨진다.이 테스트가 행을 지우지 않는 건 의도된 것이다 — 삭제가 막혔는지(409) 확인하는 테스트이므로 행이 남아야 맞다. 그래서 테스트 종료 후 정리로 해결했다.
변경 내용
HumanDeleteApiTest에@AfterEach정리를 추가했다. 이 클래스가 만든humans/certificate/certificates_issued행의 id를 추적해 역순으로 되돌린다. 이미 삭제된 행(204 테스트)은existsById로 걸러 건너뛴다.다른 테스트 파일이나 프로덕션 코드는 건드리지 않았다.
검증
양쪽 클래스 순서에서 전부 통과하는지 확인했다.
ClassOrderer$DisplayName강제 (수정 전 2개 실패)남은 것 — 구조적 문제다
같은 종류의 충돌이 이전에도 있었다. #27의
FullFlowApiTest와IssuanceHistoryApiTest가 자동 증가 id 공간에서 겹쳐 같은 방식으로 깨졌다.테스트 클래스 간 DB 격리 방침이 없으면 또 생긴다. 이번엔 누수를 낸 클래스 쪽에서 막았지만, 근본 해결은 아니다. 선택지:
@Transactional롤백 (MockMvc 통합 테스트에서는 주의 필요)@DirtiesContext별도 이슈로 다룰 가치가 있다. 이 PR 범위는 아니다.
Summary by CodeRabbit