forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
window_update_queue_test.go
90 lines (80 loc) · 2.99 KB
/
window_update_queue_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
package quic
import (
"github.com/boisjacques/qed/internal/mocks"
"github.com/boisjacques/qed/internal/protocol"
"github.com/boisjacques/qed/internal/wire"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Window Update Queue", func() {
var (
q *windowUpdateQueue
streamGetter *MockStreamGetter
connFC *mocks.MockConnectionFlowController
queuedFrames []wire.Frame
)
BeforeEach(func() {
streamGetter = NewMockStreamGetter(mockCtrl)
connFC = mocks.NewMockConnectionFlowController(mockCtrl)
queuedFrames = queuedFrames[:0]
q = newWindowUpdateQueue(streamGetter, connFC, func(f wire.Frame) {
queuedFrames = append(queuedFrames, f)
})
})
It("adds stream offsets and gets MAX_STREAM_DATA frames", func() {
stream1 := NewMockStreamI(mockCtrl)
stream1.EXPECT().getWindowUpdate().Return(protocol.ByteCount(10))
stream3 := NewMockStreamI(mockCtrl)
stream3.EXPECT().getWindowUpdate().Return(protocol.ByteCount(30))
streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(3)).Return(stream3, nil)
streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(1)).Return(stream1, nil)
q.AddStream(3)
q.AddStream(1)
q.QueueAll()
Expect(queuedFrames).To(ContainElement(&wire.MaxStreamDataFrame{StreamID: 1, ByteOffset: 10}))
Expect(queuedFrames).To(ContainElement(&wire.MaxStreamDataFrame{StreamID: 3, ByteOffset: 30}))
})
It("deletes the entry after getting the MAX_STREAM_DATA frame", func() {
stream10 := NewMockStreamI(mockCtrl)
stream10.EXPECT().getWindowUpdate().Return(protocol.ByteCount(100))
streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(10)).Return(stream10, nil)
q.AddStream(10)
q.QueueAll()
Expect(queuedFrames).To(HaveLen(1))
q.QueueAll()
Expect(queuedFrames).To(HaveLen(1))
})
It("doesn't queue a MAX_STREAM_DATA for a closed stream", func() {
streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(12)).Return(nil, nil)
q.AddStream(12)
q.QueueAll()
Expect(queuedFrames).To(BeEmpty())
})
It("doesn't queue a MAX_STREAM_DATA if the flow controller returns an offset of 0", func() {
stream5 := NewMockStreamI(mockCtrl)
stream5.EXPECT().getWindowUpdate().Return(protocol.ByteCount(0))
streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(5)).Return(stream5, nil)
q.AddStream(5)
q.QueueAll()
Expect(queuedFrames).To(BeEmpty())
})
It("queues MAX_DATA frames", func() {
connFC.EXPECT().GetWindowUpdate().Return(protocol.ByteCount(0x1337))
q.AddConnection()
q.QueueAll()
Expect(queuedFrames).To(Equal([]wire.Frame{
&wire.MaxDataFrame{ByteOffset: 0x1337},
}))
})
It("deduplicates", func() {
stream10 := NewMockStreamI(mockCtrl)
stream10.EXPECT().getWindowUpdate().Return(protocol.ByteCount(200))
streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(10)).Return(stream10, nil)
q.AddStream(10)
q.AddStream(10)
q.QueueAll()
Expect(queuedFrames).To(Equal([]wire.Frame{
&wire.MaxStreamDataFrame{StreamID: 10, ByteOffset: 200},
}))
})
})