forked from jiyeyuran/mediasoup-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter_test.go
112 lines (93 loc) · 2.53 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
102
103
104
105
106
107
108
109
110
111
112
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: 1,
ProfileLevelId: "4d0032",
},
},
},
}
func TestCreateRouter_Succeeds(t *testing.T) {
worker := CreateTestWorker()
onObserverNewRouter := NewMockFunc(t)
worker.Observer().Once("newrouter", onObserverNewRouter.Fn())
router, err := worker.CreateRouter(RouterOptions{
MediaCodecs: testRouterMediaCodecs,
})
assert.NoError(t, err)
onObserverNewRouter.ExpectCalledTimes(1)
onObserverNewRouter.ExpectCalledWith(router)
assert.False(t, router.Closed())
dump, _ := worker.Dump()
expectDump := WorkerDump{
Pid: worker.Pid(),
RouterIds: []string{router.Id()},
}
assert.Equal(t, expectDump, dump)
routerDump, _ := router.Dump()
assert.Equal(t, router.Id(), routerDump.Id)
assert.Equal(t, 1, syncMapLen(&worker.routers))
worker.Close()
assert.True(t, router.Closed())
assert.Equal(t, 0, syncMapLen(&worker.routers))
}
func TestCreateRouter_TypeError(t *testing.T) {
worker := CreateTestWorker()
_, err := worker.CreateRouter(RouterOptions{})
assert.IsType(t, err, NewTypeError(""))
}
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())
}