Skip to content

fix: 테스트 격리 개선 — dispatcher 상태 공유 및 무한 루프 위험 제거#77

Merged
gagip merged 2 commits intomainfrom
fix/test-isolation
Mar 26, 2026
Merged

fix: 테스트 격리 개선 — dispatcher 상태 공유 및 무한 루프 위험 제거#77
gagip merged 2 commits intomainfrom
fix/test-isolation

Conversation

@gagip
Copy link
Copy Markdown
Owner

@gagip gagip commented Mar 25, 2026

Summary

  • MiniPlayerViewModelTest: beforeSpecbeforeEach로 교체하여 테스트 간 Main dispatcher 상태 공유 제거. 각 테스트가 독립적인 스케줄러로 실행되도록 runTest { testScheduler } 방식으로 통일
  • ZenMusicSelectViewModelTest: polling 루프(while 무한 대기)에 maxRetries = 10 상한 추가 — 조건 미충족 시 명확한 실패 메시지로 테스트 신뢰도 향상

변경 파일

  • app/src/test/.../zen/MiniPlayerViewModelTest.kt
  • app/src/test/.../zen/musicselect/ZenMusicSelectViewModelTest.kt

- MiniPlayerViewModelTest: beforeSpec → beforeEach로 교체하여 테스트 간 Main dispatcher 상태 공유 제거
  runTest 내부에서 testScheduler 직접 사용으로 통일
- ZenMusicSelectViewModelTest: polling 루프에 maxRetries(10) 상한 추가하여 무한 대기 방지
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 25, 2026

Coverage Report

Module Coverage Covered Total
Total 19.25% 910 4727
Player 34.19% 93 272
Playlist 17.97% 71 395
Timer 48.15% 365 758
Music 21.91% 39 178

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MiniPlayerViewModelTest to use beforeEach/afterEach for Main dispatcher setup/teardown and migrated tests to runTest { ... } + testScheduler.
  • Added a maxRetries cap with a clear failure message to prevent an infinite wait loop in ZenMusicSelectViewModelTest.

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.

- coroutineTestScope = true 추가로 runTest 래핑 제거
- TestCoroutineScheduler를 Spec 레벨에서 하나만 생성해 setMain과 advanceUntilIdle이 동일 scheduler 공유
- setMain은 각 Given 블록에서 호출 (beforeEach의 불일치 방지)
- WhileSubscribed Flow 특성에 맞게 Turbine test { } 안에서 구독 → 변경 → advanceUntilIdle → awaitItem 순서 준수
- Given/When/Then 배치 규칙 정렬: When에서 액션, Then에서 검증만
@gagip gagip merged commit 20375d0 into main Mar 26, 2026
1 check passed
@gagip gagip deleted the fix/test-isolation branch March 26, 2026 00:22
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.

2 participants