forked from yutopp/go-rtmp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler_test.go
77 lines (59 loc) · 1.6 KB
/
handler_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
//
// Copyright (c) 2018- yutopp ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
//
package rtmp
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/100mslive/go-rtmp/message"
)
func TestHandlerCallback(t *testing.T) {
b := &rwcMock{}
closer := make(chan struct{})
handler := &testHandler{
t: t,
closer: closer,
}
conn := newConn(b, &ConnConfig{
Handler: handler,
SkipHandshakeVerification: true,
ReaderBufferSize: 1234,
WriterBufferSize: 1234,
ControlState: StreamControlStateConfig{
DefaultChunkSize: 1234,
MaxChunkSize: 1234,
MaxChunkStreams: 1234,
DefaultAckWindowSize: 1234,
MaxAckWindowSize: 1234,
DefaultBandwidthWindowSize: 1234,
DefaultBandwidthLimitType: message.LimitTypeHard,
MaxBandwidthWindowSize: 1234,
MaxMessageStreams: 1234,
MaxMessageSize: 1234,
},
})
sconn := newServerConn(conn)
go func() {
<-closer
sconn.Close()
}()
_ = sconn.Serve()
}
var _ Handler = (*testHandler)(nil)
type testHandler struct {
DefaultHandler
t *testing.T
closer chan struct{}
}
func (h *testHandler) OnServe(conn *Conn) {
for _, s := range []*StreamControlState{conn.streamer.PeerState(), conn.streamer.SelfState()} {
require.Equal(h.t, uint32(1234), s.ChunkSize())
require.Equal(h.t, uint32(1234), s.AckWindowSize())
require.Equal(h.t, int32(1234), s.BandwidthWindowSize())
require.Equal(h.t, message.LimitTypeHard, s.BandwidthLimitType())
}
close(h.closer) // Finish testing
}