Skip to content

Commit

Permalink
Add PlayLog test 12
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyicker committed Jun 28, 2024
1 parent b06c976 commit 0a98f7f
Showing 1 changed file with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,17 @@ internal class SingleMediaProductPlayLogTest {
}

@After
fun afterEach() = runBlocking {
val job = launch { player.playbackEngine.events.first { it is Event.Release } }
player.release()
job.join()
fun afterEach() {
try {
runBlocking {
val job = launch { player.playbackEngine.events.first { it is Event.Release } }
player.release()
job.join()
}
} catch (alreadyReleasedException: IllegalStateException) {
assertThat(alreadyReleasedException.message)
.isEqualTo("Attempt to use a released instance of SingleHandlerPlaybackEngine")
}
verify(eventSender, atMost(Int.MAX_VALUE))
.sendEvent(
argThat { !contentEquals("playback_session") },
Expand Down Expand Up @@ -733,6 +740,40 @@ internal class SingleMediaProductPlayLogTest {
)
}

@Test
fun playWithRelease() = runTest {
player.playbackEngine.load(mediaProduct)
player.playbackEngine.play()
withContext(Dispatchers.Default.limitedParallelism(1)) {
withTimeout(8.seconds) {
player.playbackEngine.events.filter { it is Event.MediaProductTransition }.first()
}
delay(1.seconds)
while (player.playbackEngine.assetPosition < 1) {
delay(10.milliseconds)
}
player.playbackEngine.release()
}

eventReporterCoroutineScope.advanceUntilIdle()
verify(eventSender).sendEvent(
eq("playback_session"),
eq(ConsentCategory.NECESSARY),
argThat {
with(Gson().fromJson(this, JsonObject::class.java)["payload"].asJsonObject) {
assertThat(get("startAssetPosition").asDouble).isAssetPositionEqualTo(0.0)
assertThat(get("endAssetPosition").asDouble).isAssetPositionEqualTo(1.0)
assertThat(get("actualProductId").asString).isEqualTo(mediaProduct.productId)
assertThat(get("sourceType")?.asString).isEqualTo(mediaProduct.sourceType)
assertThat(get("sourceId")?.asString).isEqualTo(mediaProduct.sourceId)
assertThat(get("actions").asJsonArray).isEmpty()
}
true
},
eq(emptyMap()),
)
}

private fun Assert<Double>.isAssetPositionEqualTo(targetPosition: Double) = run {
isCloseTo(targetPosition, 0.5)
}
Expand Down

0 comments on commit 0a98f7f

Please sign in to comment.