forked from cnderrauber/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ortc_datachannel_test.go
64 lines (49 loc) · 1.32 KB
/
ortc_datachannel_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
// +build !js
package webrtc
import (
"io"
"testing"
"time"
"github.com/pion/transport/test"
"github.com/stretchr/testify/assert"
)
func TestDataChannel_ORTCE2E(t *testing.T) {
lim := test.TimeOut(time.Second * 20)
defer lim.Stop()
report := test.CheckRoutines(t)
defer report()
stackA, stackB, err := newORTCPair()
assert.NoError(t, err)
awaitSetup := make(chan struct{})
awaitString := make(chan struct{})
awaitBinary := make(chan struct{})
stackB.sctp.OnDataChannel(func(d *DataChannel) {
close(awaitSetup)
d.OnMessage(func(msg DataChannelMessage) {
if msg.IsString {
close(awaitString)
} else {
close(awaitBinary)
}
})
})
assert.NoError(t, signalORTCPair(stackA, stackB))
var id uint16 = 1
dcParams := &DataChannelParameters{
Label: "Foo",
ID: &id,
}
channelA, err := stackA.api.NewDataChannel(stackA.sctp, dcParams)
assert.NoError(t, err)
<-awaitSetup
assert.NoError(t, channelA.SendText("ABC"))
assert.NoError(t, channelA.Send([]byte("ABC")))
<-awaitString
<-awaitBinary
assert.NoError(t, stackA.close())
assert.NoError(t, stackB.close())
// attempt to send when channel is closed
assert.ErrorIs(t, channelA.Send([]byte("ABC")), io.ErrClosedPipe)
assert.ErrorIs(t, channelA.SendText("test"), io.ErrClosedPipe)
assert.ErrorIs(t, channelA.ensureOpen(), io.ErrClosedPipe)
}