@@ -144,10 +144,17 @@ internal class SingleMediaProductPlayLogTest {
144144 }
145145
146146 @After
147- fun afterEach () = runBlocking {
148- val job = launch { player.playbackEngine.events.first { it is Release } }
149- player.release()
150- job.join()
147+ fun afterEach () {
148+ try {
149+ runBlocking {
150+ val job = launch { player.playbackEngine.events.first { it is Release } }
151+ player.release()
152+ job.join()
153+ }
154+ } catch (alreadyReleasedException: IllegalStateException ) {
155+ assertThat(alreadyReleasedException.message)
156+ .isEqualTo(" Attempt to use a released instance of SingleHandlerPlaybackEngine" )
157+ }
151158 verify(eventSender, atMost(Int .MAX_VALUE ))
152159 .sendEvent(
153160 argThat { ! contentEquals(" playback_session" ) },
@@ -741,6 +748,42 @@ internal class SingleMediaProductPlayLogTest {
741748 )
742749 }
743750
751+ @Test
752+ fun playWithRelease () = runTest {
753+ val gson = Gson ()
754+
755+ player.playbackEngine.load(mediaProduct)
756+ player.playbackEngine.play()
757+ withContext(Dispatchers .Default .limitedParallelism(1 )) {
758+ withTimeout(8 .seconds) {
759+ player.playbackEngine.events.filter { it is MediaProductTransition }.first()
760+ }
761+ delay(1 .seconds)
762+ while (player.playbackEngine.assetPosition < 1 ) {
763+ delay(10 .milliseconds)
764+ }
765+ player.playbackEngine.release()
766+ }
767+
768+ eventReporterCoroutineScope.advanceUntilIdle()
769+ verify(eventSender).sendEvent(
770+ eq(" playback_session" ),
771+ eq(ConsentCategory .NECESSARY ),
772+ argThat {
773+ with (gson.fromJson(this , JsonObject ::class .java)[" payload" ].asJsonObject) {
774+ assertThat(get(" startAssetPosition" ).asDouble).isAssetPositionEqualTo(0.0 )
775+ assertThat(get(" endAssetPosition" ).asDouble).isAssetPositionEqualTo(1.0 )
776+ assertThat(get(" actualProductId" ).asString).isEqualTo(mediaProduct.productId)
777+ assertThat(get(" sourceType" )?.asString).isEqualTo(mediaProduct.sourceType)
778+ assertThat(get(" sourceId" )?.asString).isEqualTo(mediaProduct.sourceId)
779+ assertThat(get(" actions" ).asJsonArray).isEmpty()
780+ }
781+ true
782+ },
783+ eq(emptyMap()),
784+ )
785+ }
786+
744787 private fun Assert<Double>.isAssetPositionEqualTo (targetPosition : Double ) = run {
745788 isCloseTo(targetPosition, 0.5 )
746789 }
0 commit comments