Skip to content

Commit

Permalink
Add PlayLog test 16
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyicker committed Jun 28, 2024
1 parent b37f002 commit c719eef
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package com.tidal.sdk.player.playlog

import assertk.Assert
import assertk.assertions.isCloseTo
import kotlin.math.absoluteValue

internal fun Assert<Double>.isAssetPositionEqualTo(targetPosition: Double) =
isCloseTo(targetPosition, 0.5)

internal fun Double.isAssetPositionEqualTo(targetPosition: Double) =
(this - targetPosition).absoluteValue < 0.5
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,75 @@ internal class SingleMediaProductPlayLogTest {
eq(emptyMap()),
)
}

@Test
fun seekBeyondBoundsWithRepeatOne() = runTest {
val gson = Gson()

player.playbackEngine.load(mediaProduct)
player.playbackEngine.setRepeatOne(true)
player.playbackEngine.play()
withContext(Dispatchers.Default.limitedParallelism(1)) {
delay(2.seconds)
while (player.playbackEngine.assetPosition < 2) {
delay(10.milliseconds)
}
player.playbackEngine.seek(10_000F)
delay(1.seconds)
while (player.playbackEngine.assetPosition < 1) {
delay(10.milliseconds)
}
player.playbackEngine.reset()
}

eventReporterCoroutineScope.advanceUntilIdle()
verify(eventSender).sendEvent(
eq("playback_session"),
eq(ConsentCategory.NECESSARY),
argThat {
with(gson.fromJson(this, JsonObject::class.java)["payload"].asJsonObject) {
get("startAssetPosition").asDouble.isAssetPositionEqualTo(0.0) &&
get("endAssetPosition").asDouble
.isAssetPositionEqualTo(MEDIA_PRODUCT_DURATION_SECONDS) &&
get("actualProductId")?.asString.contentEquals(mediaProduct.productId) &&
get("sourceType")?.asString.contentEquals(mediaProduct.sourceType) &&
get("sourceId")?.asString.contentEquals(mediaProduct.sourceId) &&
get("actions").asJsonArray.run {
val stopAction =
gson.fromJson(this[0], PlaybackSession.Payload.Action::class.java)
val startAction =
gson.fromJson(this[1], PlaybackSession.Payload.Action::class.java)
val perfectResumeTimestamp = stopAction.timestamp
stopAction.actionType ==
PlaybackSession.Payload.Action.Type.PLAYBACK_STOP &&
stopAction.assetPositionSeconds.isAssetPositionEqualTo(2.0) &&
startAction.actionType ==
PlaybackSession.Payload.Action.Type.PLAYBACK_START &&
startAction.assetPositionSeconds
.isAssetPositionEqualTo(MEDIA_PRODUCT_DURATION_SECONDS) &&
startAction.timestamp in
(perfectResumeTimestamp - 500)..(perfectResumeTimestamp + 500)
}
}
},
eq(emptyMap()),
)
verify(eventSender).sendEvent(
eq("playback_session"),
eq(ConsentCategory.NECESSARY),
argThat {
with(gson.fromJson(this, JsonObject::class.java)["payload"].asJsonObject) {
get("startAssetPosition").asDouble.isAssetPositionEqualTo(0.0) &&
get("endAssetPosition").asDouble.isAssetPositionEqualTo(1.0) &&
get("actualProductId")?.asString.contentEquals(mediaProduct.productId) &&
get("sourceType")?.asString.contentEquals(mediaProduct.sourceType) &&
get("sourceId")?.asString.contentEquals(mediaProduct.sourceId) &&
get("actions").asJsonArray.isEmpty
}
},
eq(emptyMap()),
)
}
}

private const val MEDIA_PRODUCT_DURATION_SECONDS = 5.055
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.tidal.sdk.player.playbackengine.model.Event
import com.tidal.sdk.player.playbackengine.model.Event.MediaProductEnded
import com.tidal.sdk.player.playbackengine.model.Event.Release
import com.tidal.sdk.player.setBodyFromFile
import kotlin.math.absoluteValue
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -301,7 +300,4 @@ internal class TwoMediaProductsPlayLogTest {
eq(emptyMap()),
)
}

private fun Double.isAssetPositionEqualTo(targetPosition: Double) =
(this - targetPosition).absoluteValue < 0.5
}

0 comments on commit c719eef

Please sign in to comment.