From eb6b08ff568be22e2584a3c57f922d9ccffe3465 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Sun, 27 Sep 2026 06:20:07 +0000 Subject: [PATCH] replace the seed-flaky block test and cover clearing the block while shuffled `removingThePlayingTrackWhileShuffledLeavesTheBlockReachable` looped 30 unseeded shuffles and only checked a weak invariant; it is now a single deterministic case (fixed seed) that asserts the cursor resolves to the playing track and the queued track still plays next. Add clearing the block while shuffled, asserting the cursor stays on the playing track. --- .../playback/PlaybackControllerTest.kt | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/app/src/test/kotlin/com/subtracks/playback/PlaybackControllerTest.kt b/app/src/test/kotlin/com/subtracks/playback/PlaybackControllerTest.kt index 94355911..3d266a38 100644 --- a/app/src/test/kotlin/com/subtracks/playback/PlaybackControllerTest.kt +++ b/app/src/test/kotlin/com/subtracks/playback/PlaybackControllerTest.kt @@ -1701,35 +1701,43 @@ class PlaybackControllerTest { fun removingThePlayingTrackWhileShuffledLeavesTheBlockReachable() { seedAlbum(6, sourceId = 1) seedSong("x1", "al2") - - repeat(30) { - if (controller.state.value.shuffle) { - controller.toggleShuffle() - await { !controller.state.value.shuffle } - } - runBlocking { controller.clearUpNext() } - controller.playAlbum(1, "al1", 2) - await { - controller.state.value.item - ?.id == "s3" && !controller.state.value.shuffle - } - controller.addToQueue(1, QueueKind.Song, "x1") - await { runBlocking { controller.upcomingItem()?.id } == "x1" } - - controller.toggleShuffle() - await { controller.state.value.shuffle } - await { runBlocking { controller.upcomingItem()?.id } == "x1" } - val current = controller.state.value.position!! - - runBlocking { controller.removeAt(current) } - - val snapshot = runBlocking { queues.snapshot() } - val position = controller.state.value.position!! - assertTrue( - "queued track stranded behind the cursor at $position (block at ${snapshot.anchorPlay})", - position <= snapshot.anchorPlay || snapshot.isUpNext(position), - ) + runBlocking { + queues.replace(listOf(queues.albumEntry(1, "al1"))) + queues.setShuffle(2024L) + queues.setCursor(0) } + controller.connect() + await { controller.state.value.item != null && controller.state.value.shuffle } + controller.addToQueue(1, QueueKind.Song, "x1") + await { runBlocking { controller.upcomingItem()?.id } == "x1" } + + val current = controller.state.value.position!! + runBlocking { controller.removeAt(current) } + + val after = runBlocking { queues.snapshot() } + assertTrue(after.shuffled) + assertEquals( + controller.state.value.item + ?.id, + runBlocking { queues.itemAt(after, controller.state.value.position!!)?.song?.id }, + ) + await { runBlocking { controller.upcomingItem()?.id } == "x1" } + } + + @Test + fun clearingTheBlockWhileShuffledKeepsTheCursorOnThePlayingTrack() { + seedShuffledQueue(seed = 7L) + val currentId = + controller.state.value.item!! + .id + controller.addToQueue(1, QueueKind.Song, "s1") + await { runBlocking { controller.upcomingItem()?.id } == "s1" } + + controller.clearUpNext() + + await { runBlocking { queues.snapshot().upNext }.isEmpty() } + val after = runBlocking { queues.snapshot() } + assertEquals(currentId, runBlocking { queues.itemAt(after, controller.state.value.position!!)?.song?.id }) } @Test