@@ -47,6 +47,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
4747import  kotlinx.coroutines.Job 
4848import  kotlinx.coroutines.cancel 
4949import  kotlinx.coroutines.launch 
50+ import  kotlinx.coroutines.test.StandardTestDispatcher 
5051import  kotlinx.coroutines.test.advanceUntilIdle 
5152import  livekit.LivekitModels 
5253import  livekit.LivekitModels.AudioTrackFeature 
@@ -67,6 +68,7 @@ import org.mockito.kotlin.argThat
6768import  org.robolectric.RobolectricTestRunner 
6869import  org.robolectric.Shadows 
6970import  java.nio.ByteBuffer 
71+ import  kotlin.time.Duration.Companion.seconds 
7072
7173@ExperimentalCoroutinesApi
7274@RunWith(RobolectricTestRunner ::class )
@@ -123,11 +125,23 @@ class LocalParticipantMockE2ETest : MockE2ETest() {
123125        wsFactory.unregisterSignalRequestHandler(wsFactory.defaultSignalRequestHandler)
124126        wsFactory.ws.clearRequests()
125127
126-         val  backgroundScope =  CoroutineScope (coroutineContext +  Job ())
128+         val  standardTestDispatcher =  StandardTestDispatcher ()
129+         val  backgroundScope =  CoroutineScope (coroutineContext +  Job () +  standardTestDispatcher)
127130        try  {
128-             backgroundScope.launch { room.localParticipant.setMicrophoneEnabled(true ) }
129-             backgroundScope.launch { room.localParticipant.setMicrophoneEnabled(true ) }
131+             backgroundScope.launch {
132+                 try  {
133+                     room.localParticipant.setMicrophoneEnabled(true )
134+                 } catch  (_:  Exception ) {
135+                 }
136+             }
137+             backgroundScope.launch {
138+                 try  {
139+                     room.localParticipant.setMicrophoneEnabled(true )
140+                 } catch  (_:  Exception ) {
141+                 }
142+             }
130143
144+             standardTestDispatcher.scheduler.advanceTimeBy(1 .seconds.inWholeMilliseconds)
131145            assertEquals(1 , wsFactory.ws.sentRequests.size)
132146        } finally  {
133147            backgroundScope.cancel()
@@ -145,10 +159,23 @@ class LocalParticipantMockE2ETest : MockE2ETest() {
145159        wsFactory.unregisterSignalRequestHandler(wsFactory.defaultSignalRequestHandler)
146160        wsFactory.ws.clearRequests()
147161
148-         val  backgroundScope =  CoroutineScope (coroutineContext +  Job ())
162+         val  standardTestDispatcher =  StandardTestDispatcher ()
163+         val  backgroundScope =  CoroutineScope (coroutineContext +  Job () +  standardTestDispatcher)
149164        try  {
150-             backgroundScope.launch { room.localParticipant.setMicrophoneEnabled(true ) }
151-             backgroundScope.launch { room.localParticipant.setCameraEnabled(true ) }
165+             backgroundScope.launch {
166+                 try  {
167+                     room.localParticipant.setMicrophoneEnabled(true )
168+                 } catch  (_:  Exception ) {
169+                 }
170+             }
171+             backgroundScope.launch {
172+                 try  {
173+                     room.localParticipant.setCameraEnabled(true )
174+                 } catch  (_:  Exception ) {
175+                 }
176+             }
177+ 
178+             standardTestDispatcher.scheduler.advanceTimeBy(1 .seconds.inWholeMilliseconds)
152179
153180            assertEquals(2 , wsFactory.ws.sentRequests.size)
154181        } finally  {
@@ -562,4 +589,22 @@ class LocalParticipantMockE2ETest : MockE2ETest() {
562589
563590        assertTrue(didThrow)
564591    }
592+ 
593+     @Test
594+     fun  publishWithNoResponseCausesException () =  runTest {
595+         connect()
596+ 
597+         wsFactory.unregisterSignalRequestHandler(wsFactory.defaultSignalRequestHandler)
598+         var  didThrow =  false 
599+         launch {
600+             try  {
601+                 room.localParticipant.publishVideoTrack(createLocalTrack())
602+             } catch  (e:  TrackException .PublishException ) {
603+                 didThrow =  true 
604+             }
605+         }
606+ 
607+         coroutineRule.dispatcher.scheduler.advanceUntilIdle()
608+         assertTrue(didThrow)
609+     }
565610}
0 commit comments