Skip to content

test: add SyncAudioPlayer unit tests#78

Merged
chrisuthe merged 4 commits intomainfrom
test/sync-audio-player-unit-tests
Mar 8, 2026
Merged

test: add SyncAudioPlayer unit tests#78
chrisuthe merged 4 commits intomainfrom
test/sync-audio-player-unit-tests

Conversation

@chrisuthe
Copy link
Copy Markdown
Owner

Summary

  • Add 31 unit tests for SyncAudioPlayer covering the playback state machine, sync correction logic, gap/overlap handling, and pre-sync buffering
  • Tests use MockK for SendspinTimeFilter and reflection for internal state verification since AudioTrack is unavailable in JVM unit tests
  • Test file: android/app/src/test/java/com/sendspindroid/sendspin/SyncAudioPlayerTest.kt

Tests added (grouped by area):

State transitions & draining (tests 1-3)

  • INITIALIZING -> WAITING_FOR_START on first chunk
  • DRAINING state entry/rejection and buffer exhaustion detection
  • Reanchor 5-second cooldown enforcement

Thread safety & correction guards (tests 4-6)

  • Concurrent enterDraining/exitDraining thread safety
  • Correction rate clamped to MAX_SPEED_CORRECTION (+/-2%)
  • No corrections during 500ms startup grace period

Reconnect & stream continuity (tests 7-9)

  • No corrections during 2-second reconnect stabilization
  • Gap >10ms filled with silence; small gaps pass through
  • Overlapping chunks trimmed; complete overlaps skipped

Buffering & timing infrastructure (tests 10-12)

  • Pre-sync chunk buffering up to MAX_PENDING_CHUNKS (500)
  • Frame position 32-bit wrap detection
  • 5-second baseline refresh interval and reset on clearBuffer

Test plan

  • All 31 tests pass locally (./gradlew :app:testDebugUnitTest --tests "com.sendspindroid.sendspin.SyncAudioPlayerTest")
  • CI passes

Add unit tests for INIT->WAITING_FOR_START transition, DRAINING state
buffer exhaustion detection, and reanchor 5-second cooldown enforcement.
Add tests for concurrent enterDraining/exitDraining thread safety,
MAX_SPEED_CORRECTION (+/-2%) clamping for insert/drop rates, and
suppression of corrections during the 500ms startup grace period.
Add tests for 2-second reconnect stabilization guard, silence fill for
gaps >10ms, small gap passthrough, overlap trimming, and complete
overlap chunk skipping.
Add tests for pre-sync chunk buffering with MAX_PENDING_CHUNKS limit,
32-bit frame position wrap detection, 5-second baseline refresh
interval, and additional state machine edge cases.
@chrisuthe chrisuthe merged commit 0f141f3 into main Mar 8, 2026
@chrisuthe chrisuthe deleted the test/sync-audio-player-unit-tests branch March 8, 2026 03:11
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