Skip to content

Commit 0a98f7f

Browse files
committed
Add PlayLog test 12
1 parent b06c976 commit 0a98f7f

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

player/src/androidTest/kotlin/com/tidal/sdk/player/playlog/SingleMediaProductPlayLogTest.kt

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,17 @@ internal class SingleMediaProductPlayLogTest {
142142
}
143143

144144
@After
145-
fun afterEach() = runBlocking {
146-
val job = launch { player.playbackEngine.events.first { it is Event.Release } }
147-
player.release()
148-
job.join()
145+
fun afterEach() {
146+
try {
147+
runBlocking {
148+
val job = launch { player.playbackEngine.events.first { it is Event.Release } }
149+
player.release()
150+
job.join()
151+
}
152+
} catch (alreadyReleasedException: IllegalStateException) {
153+
assertThat(alreadyReleasedException.message)
154+
.isEqualTo("Attempt to use a released instance of SingleHandlerPlaybackEngine")
155+
}
149156
verify(eventSender, atMost(Int.MAX_VALUE))
150157
.sendEvent(
151158
argThat { !contentEquals("playback_session") },
@@ -733,6 +740,40 @@ internal class SingleMediaProductPlayLogTest {
733740
)
734741
}
735742

743+
@Test
744+
fun playWithRelease() = runTest {
745+
player.playbackEngine.load(mediaProduct)
746+
player.playbackEngine.play()
747+
withContext(Dispatchers.Default.limitedParallelism(1)) {
748+
withTimeout(8.seconds) {
749+
player.playbackEngine.events.filter { it is Event.MediaProductTransition }.first()
750+
}
751+
delay(1.seconds)
752+
while (player.playbackEngine.assetPosition < 1) {
753+
delay(10.milliseconds)
754+
}
755+
player.playbackEngine.release()
756+
}
757+
758+
eventReporterCoroutineScope.advanceUntilIdle()
759+
verify(eventSender).sendEvent(
760+
eq("playback_session"),
761+
eq(ConsentCategory.NECESSARY),
762+
argThat {
763+
with(Gson().fromJson(this, JsonObject::class.java)["payload"].asJsonObject) {
764+
assertThat(get("startAssetPosition").asDouble).isAssetPositionEqualTo(0.0)
765+
assertThat(get("endAssetPosition").asDouble).isAssetPositionEqualTo(1.0)
766+
assertThat(get("actualProductId").asString).isEqualTo(mediaProduct.productId)
767+
assertThat(get("sourceType")?.asString).isEqualTo(mediaProduct.sourceType)
768+
assertThat(get("sourceId")?.asString).isEqualTo(mediaProduct.sourceId)
769+
assertThat(get("actions").asJsonArray).isEmpty()
770+
}
771+
true
772+
},
773+
eq(emptyMap()),
774+
)
775+
}
776+
736777
private fun Assert<Double>.isAssetPositionEqualTo(targetPosition: Double) = run {
737778
isCloseTo(targetPosition, 0.5)
738779
}

0 commit comments

Comments
 (0)