forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icegatherer_test.go
116 lines (94 loc) · 2.35 KB
/
icegatherer_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
113
114
115
116
// +build !js
package webrtc
import (
"testing"
"time"
"github.com/pion/logging"
"github.com/pion/transport/test"
)
func TestNewICEGatherer_Success(t *testing.T) {
// Limit runtime in case of deadlocks
lim := test.TimeOut(time.Second * 20)
defer lim.Stop()
report := test.CheckRoutines(t)
defer report()
opts := ICEGatherOptions{
ICEServers: []ICEServer{{URLs: []string{"stun:stun.l.google.com:19302"}}},
}
gatherer, err := NewICEGatherer(0, 0, nil, nil, nil, nil, nil, nil, nil, logging.NewDefaultLoggerFactory(), false, nil, opts)
if err != nil {
t.Error(err)
}
if gatherer.State() != ICEGathererStateNew {
t.Fatalf("Expected gathering state new")
}
err = gatherer.Gather()
if err != nil {
t.Error(err)
}
params, err := gatherer.GetLocalParameters()
if err != nil {
t.Error(err)
}
if len(params.UsernameFragment) == 0 ||
len(params.Password) == 0 {
t.Fatalf("Empty local username or password frag")
}
candidates, err := gatherer.GetLocalCandidates()
if err != nil {
t.Error(err)
}
if len(candidates) == 0 {
t.Fatalf("No candidates gathered")
}
err = gatherer.Close()
if err != nil {
t.Error(err)
}
}
func TestICEGather_LocalCandidateOrder(t *testing.T) {
// Limit runtime in case of deadlocks
lim := test.TimeOut(time.Second * 20)
defer lim.Stop()
opts := ICEGatherOptions{
ICEServers: []ICEServer{{URLs: []string{"stun:stun.l.google.com:19302"}}},
}
to := time.Second
gatherer, err := NewICEGatherer(10000, 10010, &to, &to, &to, &to, &to, &to, &to, logging.NewDefaultLoggerFactory(), false, []NetworkType{NetworkTypeUDP4}, opts)
if err != nil {
t.Error(err)
}
if gatherer.State() != ICEGathererStateNew {
t.Fatalf("Expected gathering state new")
}
for i := 0; i < 10; i++ {
candidate := make(chan *ICECandidate)
gatherer.OnLocalCandidate(func(c *ICECandidate) {
candidate <- c
})
if err := gatherer.SignalCandidates(); err != nil {
t.Error(err)
}
endGathering := false
L:
for {
select {
case c := <-candidate:
if c == nil {
endGathering = true
} else if endGathering {
t.Error("Received a candidate after the last candidate")
break L
}
case <-time.After(100 * time.Millisecond):
if !endGathering {
t.Error("Timed out before receiving the last candidate")
}
break L
}
}
}
if err := gatherer.Close(); err != nil {
t.Error(err)
}
}