forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icetransport_test.go
74 lines (55 loc) · 2.01 KB
/
icetransport_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
//go:build !js
// +build !js
package webrtc
import (
"sync/atomic"
"testing"
"time"
"github.com/pion/transport/test"
"github.com/stretchr/testify/assert"
)
func TestICETransport_OnSelectedCandidatePairChange(t *testing.T) {
report := test.CheckRoutines(t)
defer report()
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()
pcOffer, pcAnswer, err := newPair()
assert.NoError(t, err)
iceComplete := make(chan bool)
pcAnswer.OnICEConnectionStateChange(func(iceState ICEConnectionState) {
if iceState == ICEConnectionStateConnected {
time.Sleep(3 * time.Second)
close(iceComplete)
}
})
senderCalledCandidateChange := int32(0)
pcOffer.SCTP().Transport().ICETransport().OnSelectedCandidatePairChange(func(pair *ICECandidatePair) {
atomic.StoreInt32(&senderCalledCandidateChange, 1)
})
assert.NoError(t, signalPair(pcOffer, pcAnswer))
<-iceComplete
if atomic.LoadInt32(&senderCalledCandidateChange) == 0 {
t.Fatalf("Sender ICETransport OnSelectedCandidateChange was never called")
}
closePairNow(t, pcOffer, pcAnswer)
}
func TestICETransport_GetSelectedCandidatePair(t *testing.T) {
offerer, answerer, err := newPair()
assert.NoError(t, err)
peerConnectionConnected := untilConnectionState(PeerConnectionStateConnected, offerer, answerer)
offererSelectedPair, err := offerer.SCTP().Transport().ICETransport().GetSelectedCandidatePair()
assert.NoError(t, err)
assert.Nil(t, offererSelectedPair)
answererSelectedPair, err := answerer.SCTP().Transport().ICETransport().GetSelectedCandidatePair()
assert.NoError(t, err)
assert.Nil(t, answererSelectedPair)
assert.NoError(t, signalPair(offerer, answerer))
peerConnectionConnected.Wait()
offererSelectedPair, err = offerer.SCTP().Transport().ICETransport().GetSelectedCandidatePair()
assert.NoError(t, err)
assert.NotNil(t, offererSelectedPair)
answererSelectedPair, err = answerer.SCTP().Transport().ICETransport().GetSelectedCandidatePair()
assert.NoError(t, err)
assert.NotNil(t, answererSelectedPair)
closePairNow(t, offerer, answerer)
}