RTCEngineMockE2ETest.kt
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package io.livekit.android.room
import io.livekit.android.MockE2ETest
import io.livekit.android.mock.MockPeerConnection
import io.livekit.android.util.toOkioByteString
import io.livekit.android.util.toPBByteString
import kotlinx.coroutines.ExperimentalCoroutinesApi
import livekit.LivekitRtc
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.webrtc.PeerConnection
@ExperimentalCoroutinesApi
@RunWith(RobolectricTestRunner::class)
class RTCEngineMockE2ETest : MockE2ETest() {
lateinit var rtcEngine: RTCEngine
@Before
fun setupRTCEngine() {
rtcEngine = component.rtcEngine()
}
@Test
fun iceSubscriberConnect() = runTest {
connect()
Assert.assertEquals(
SignalClientTest.OFFER.offer.sdp,
rtcEngine.subscriber.peerConnection.remoteDescription.description
)
val ws = wsFactory.ws
val sentRequest = LivekitRtc.SignalRequest.newBuilder()
.mergeFrom(ws.sentRequests[0].toPBByteString())
.build()
val subPeerConnection = rtcEngine.subscriber.peerConnection as MockPeerConnection
val localAnswer = subPeerConnection.localDescription ?: throw IllegalStateException("no answer was created.")
Assert.assertTrue(sentRequest.hasAnswer())
Assert.assertEquals(localAnswer.description, sentRequest.answer.sdp)
Assert.assertEquals(localAnswer.type.canonicalForm(), sentRequest.answer.type)
Assert.assertEquals(ConnectionState.CONNECTED, rtcEngine.connectionState)
}
@Test
fun reconnectOnFailure() = runTest {
connect()
val oldWs = wsFactory.ws
wsFactory.listener.onFailure(oldWs, Exception(), null)
val newWs = wsFactory.ws
Assert.assertNotEquals(oldWs, newWs)
}
@Test
fun reconnectOnSubscriberFailure() = runTest {
connect()
val oldWs = wsFactory.ws
val subPeerConnection = rtcEngine.subscriber.peerConnection as MockPeerConnection
subPeerConnection.moveToIceConnectionState(PeerConnection.IceConnectionState.FAILED)
val newWs = wsFactory.ws
Assert.assertNotEquals(oldWs, newWs)
}
@Test
fun reconnectOnPublisherFailure() = runTest {
connect()
val oldWs = wsFactory.ws
val pubPeerConnection = rtcEngine.publisher.peerConnection as MockPeerConnection
pubPeerConnection.moveToIceConnectionState(PeerConnection.IceConnectionState.FAILED)
val newWs = wsFactory.ws
Assert.assertNotEquals(oldWs, newWs)
}
@Test
fun refreshToken() = runTest {
connect()
val oldToken = wsFactory.request.url.queryParameter(SignalClient.CONNECT_QUERY_TOKEN)
wsFactory.listener.onMessage(wsFactory.ws, SignalClientTest.REFRESH_TOKEN.toOkioByteString())
wsFactory.listener.onFailure(wsFactory.ws, Exception(), null)
val newToken = wsFactory.request.url.queryParameter(SignalClient.CONNECT_QUERY_TOKEN)
Assert.assertNotEquals(oldToken, newToken)
Assert.assertEquals(SignalClientTest.REFRESH_TOKEN.refreshToken, newToken)
}
}