-
Notifications
You must be signed in to change notification settings - Fork 43
/
router_test.go
101 lines (85 loc) · 2.24 KB
/
router_test.go
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
96
97
98
99
100
101
package mediasoup
import (
"testing"
"github.com/jiyeyuran/mediasoup-go/h264"
"github.com/stretchr/testify/assert"
)
var testRouterMediaCodecs = []*RtpCodecCapability{
{
Kind: "audio",
MimeType: "audio/opus",
ClockRate: 48000,
Channels: 2,
Parameters: RtpCodecSpecificParameters{
Useinbandfec: 1,
},
},
{
Kind: "video",
MimeType: "video/VP8",
ClockRate: 90000,
},
{
Kind: "video",
MimeType: "video/H264",
ClockRate: 90000,
Parameters: RtpCodecSpecificParameters{
RtpParameter: h264.RtpParameter{
LevelAsymmetryAllowed: 1,
PacketizationMode: Uint8(1),
ProfileLevelId: "4d0032",
},
},
},
}
func TestCreateRouter_Succeeds(t *testing.T) {
worker := CreateTestWorker()
router, err := worker.CreateRouter(RouterOptions{
MediaCodecs: testRouterMediaCodecs,
})
assert.NoError(t, err)
assert.False(t, router.Closed())
dump, _ := worker.Dump()
expectDump := WorkerDump{
Pid: worker.Pid(),
RouterIds: []string{router.Id()},
WebRtcServerIds: []string{},
}
assert.Equal(t, expectDump, dump)
routerDump, _ := router.Dump()
assert.Equal(t, router.Id(), routerDump.Id)
assert.EqualValues(t, 1, syncMapLen(&worker.routers))
worker.Close()
assert.True(t, router.Closed())
assert.EqualValues(t, 0, syncMapLen(&worker.routers))
}
func TestCreateRouter_InvalidStateError(t *testing.T) {
worker := CreateTestWorker()
worker.Close()
_, err := worker.CreateRouter(RouterOptions{
MediaCodecs: testRouterMediaCodecs,
})
assert.Error(t, err, NewInvalidStateError(""))
}
func TestRouterClose_Succeeds(t *testing.T) {
worker := CreateTestWorker()
onObserverClose := NewMockFunc(t)
router, _ := worker.CreateRouter(RouterOptions{
MediaCodecs: testRouterMediaCodecs,
})
router.Observer().Once("close", onObserverClose.Fn())
router.Close()
onObserverClose.ExpectCalled()
assert.True(t, router.Closed())
}
func TestRouterEmitsWorkCloseIfWorkerIsClosed(t *testing.T) {
worker := CreateTestWorker()
onObserverClose := NewMockFunc(t)
router, _ := worker.CreateRouter(RouterOptions{
MediaCodecs: testRouterMediaCodecs,
})
router.Observer().Once("close", onObserverClose.Fn())
worker.Close()
onObserverClose.ExpectCalled()
assert.True(t, router.Closed())
}