Skip to content

Commit

Permalink
Introduce exception type for post-release PlaybackEngine usage attempts
Browse files Browse the repository at this point in the history
This allows for a more robust test as well as easier host-side checks.
  • Loading branch information
stoyicker committed Jun 27, 2024
1 parent b37d39d commit b09bf4b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tidal.sdk.player.common

class PlaybackEngineUsageAfterReleaseException :
IllegalStateException("Attempted to use a released PlaybackEngine")
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tidal.sdk.player.playbackengine

import android.os.Handler
import com.tidal.sdk.player.common.PlaybackEngineUsageAfterReleaseException
import com.tidal.sdk.player.common.model.AudioQuality
import com.tidal.sdk.player.common.model.LoudnessNormalizationMode
import com.tidal.sdk.player.common.model.MediaProduct
Expand Down Expand Up @@ -78,8 +79,7 @@ internal class SingleHandlerPlaybackEngine(

private fun postOrThrow(runnable: Runnable) {
if (!handler.post(runnable)) {
val className = SingleHandlerPlaybackEngine::class.simpleName
error("Attempt to use a released instance of $className")
throw PlaybackEngineUsageAfterReleaseException()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ internal class ExoPlayerPlaybackEngineTest {

playbackEngine.release()

verify(initialExtendedExoPlayer).currentPositionMs
verify(initialExtendedExoPlayer).release()
verifyNoMoreInteractions(initialExtendedExoPlayer, looper)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.tidal.sdk.common.TidalMessage
import com.tidal.sdk.eventproducer.EventSender
import com.tidal.sdk.eventproducer.model.ConsentCategory
import com.tidal.sdk.player.Player
import com.tidal.sdk.player.common.PlaybackEngineUsageAfterReleaseException
import com.tidal.sdk.player.common.model.MediaProduct
import com.tidal.sdk.player.common.model.ProductType
import com.tidal.sdk.player.events.EventReporterModuleRoot
Expand Down Expand Up @@ -151,9 +152,10 @@ internal class SingleMediaProductPlayLogTest {
player.release()
job.join()
}
} catch (alreadyReleasedException: IllegalStateException) {
assertThat(alreadyReleasedException.message)
.isEqualTo("Attempt to use a released instance of SingleHandlerPlaybackEngine")
} catch (throwable: Throwable) {
if (throwable !is PlaybackEngineUsageAfterReleaseException) {
throw throwable
}
}
verify(eventSender, atMost(Int.MAX_VALUE))
.sendEvent(
Expand Down

0 comments on commit b09bf4b

Please sign in to comment.