Skip to content

bug: 테스트 픽스처 누수로 클래스 순서에 따라 테스트가 깨지는 문제 (#74) - #75

Merged
cowtree28 merged 1 commit into
developfrom
bug/74-test-fixture-leak
Oct 6, 2026
Merged

cowtree28 merged 1 commit into
developfrom
bug/74-test-fixture-leak

Conversation

@cowtree28

@cowtree28 cowtree28 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

개요

HumanDeleteApiTest(#64에서 추가)가 공유 테스트 DB에 남긴 픽스처 때문에 클래스 실행 순서가 바뀌면 IssuanceHistoryApiTest 2개가 깨지던 문제를 고친다.

Closes #74

왜 지금 CI는 초록인가

테스트 DB가 테스트 JVM 전체에서 하나이고(jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1), JUnit 기본 클래스 순서가 우연히 IssuanceHistoryApiTest → HumanDeleteApiTest라서 통과하고 있었다. 순서만 뒤집으면 바로 깨진다.

IssuanceHistoryApiTest > endDate_없이_startDate만으로_조회() FAILED
IssuanceHistoryApiTest > 발급_이력_전체_조회_최신순() FAILED
119 tests completed, 2 failed

원인

발급_건이_있으면_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로 걸러 건너뛴다.

다른 테스트 파일이나 프로덕션 코드는 건드리지 않았다.

검증

양쪽 클래스 순서에서 전부 통과하는지 확인했다.

조건 결과
기본 순서 119개 통과, 실패 0
ClassOrderer$DisplayName 강제 (수정 전 2개 실패) 119개 통과, 실패 0

남은 것 — 구조적 문제다

같은 종류의 충돌이 이전에도 있었다. #27의 FullFlowApiTest와 IssuanceHistoryApiTest가 자동 증가 id 공간에서 겹쳐 같은 방식으로 깨졌다.

테스트 클래스 간 DB 격리 방침이 없으면 또 생긴다. 이번엔 누수를 낸 클래스 쪽에서 막았지만, 근본 해결은 아니다. 선택지:

  • @Transactional 롤백 (MockMvc 통합 테스트에서는 주의 필요)
  • 클래스별 DB 분리 또는 @DirtiesContext
  • 공용 픽스처를 한 곳에 모으고 각 테스트는 자기 데이터만 쓰기

별도 이슈로 다룰 가치가 있다. 이 PR 범위는 아니다.

Summary by CodeRabbit

  • Tests
    • Automated checks now remove test-created human and certificate records after each run, reducing leftover test data. They continue to verify successful deletion when no related records exist, and conflict responses with records retained when certificate data is linked. These changes affect test cleanup and verification; no end-user functionality has changed.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2a9ba05f-30b7-40f8-8172-37f4b9e7dbba
📥 Commits

Reviewing files that changed from the base of the PR and between f646f5f and afb328c.

📒 Files selected for processing (1)
  • src/test/java/commonly/commonlybe/human/HumanDeleteApiTest.java
 ___________________________
< Goodbye, pre-merge panic. >
 ---------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cowtree28
cowtree28 merged commit 5b1238d into develop Oct 6, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

테스트 픽스처 누수로 클래스 실행 순서에 따라 테스트가 깨진다

1 participant