fix: 테스트 격리 개선 — dispatcher 상태 공유 및 무한 루프 위험 제거#77
Merged
Conversation
- MiniPlayerViewModelTest: beforeSpec → beforeEach로 교체하여 테스트 간 Main dispatcher 상태 공유 제거 runTest 내부에서 testScheduler 직접 사용으로 통일 - ZenMusicSelectViewModelTest: polling 루프에 maxRetries(10) 상한 추가하여 무한 대기 방지
Coverage Report
|
There was a problem hiding this comment.
Pull request overview
This PR improves coroutine-based test stability and isolation by preventing shared Main dispatcher state across tests and bounding a previously unbounded polling loop in a ViewModel test.
Changes:
- Updated
MiniPlayerViewModelTestto usebeforeEach/afterEachfor Main dispatcher setup/teardown and migrated tests torunTest { ... }+testScheduler. - Added a
maxRetriescap with a clear failure message to prevent an infinite wait loop inZenMusicSelectViewModelTest.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| app/src/test/java/com/happyseal/zenplayer/zen/musicselect/ZenMusicSelectViewModelTest.kt | Adds bounded retry logic (max retries + failure message) to avoid unbounded polling in a Turbine collection. |
| app/src/test/java/com/happyseal/zenplayer/zen/MiniPlayerViewModelTest.kt | Moves Main dispatcher setup to per-test hooks and switches tests to runTest {} + testScheduler usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
app/src/test/java/com/happyseal/zenplayer/zen/MiniPlayerViewModelTest.kt
Outdated
Show resolved
Hide resolved
- coroutineTestScope = true 추가로 runTest 래핑 제거
- TestCoroutineScheduler를 Spec 레벨에서 하나만 생성해 setMain과 advanceUntilIdle이 동일 scheduler 공유
- setMain은 각 Given 블록에서 호출 (beforeEach의 불일치 방지)
- WhileSubscribed Flow 특성에 맞게 Turbine test { } 안에서 구독 → 변경 → advanceUntilIdle → awaitItem 순서 준수
- Given/When/Then 배치 규칙 정렬: When에서 액션, Then에서 검증만
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.
Summary
MiniPlayerViewModelTest:beforeSpec→beforeEach로 교체하여 테스트 간 Main dispatcher 상태 공유 제거. 각 테스트가 독립적인 스케줄러로 실행되도록runTest { testScheduler }방식으로 통일ZenMusicSelectViewModelTest: polling 루프(while무한 대기)에maxRetries = 10상한 추가 — 조건 미충족 시 명확한 실패 메시지로 테스트 신뢰도 향상변경 파일
app/src/test/.../zen/MiniPlayerViewModelTest.ktapp/src/test/.../zen/musicselect/ZenMusicSelectViewModelTest.kt