forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_queue_test.go
66 lines (54 loc) · 1.26 KB
/
send_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
package quic
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Send Queue", func() {
var q *sendQueue
var c *mockConnection
BeforeEach(func() {
c = newMockConnection()
q = newSendQueue(c)
})
getPacket := func(b []byte) *packedPacket {
buf := getPacketBuffer()
buf.Slice = buf.Slice[:len(b)]
copy(buf.Slice, b)
return &packedPacket{
buffer: buf,
raw: buf.Slice,
}
}
It("sends a packet", func() {
q.Send(getPacket([]byte("foobar")))
done := make(chan struct{})
go func() {
defer GinkgoRecover()
q.Run()
close(done)
}()
Eventually(c.written).Should(Receive(Equal([]byte("foobar"))))
q.Close()
Eventually(done).Should(BeClosed())
})
It("blocks sending when too many packets are queued", func() {
q.Send(getPacket([]byte("foobar")))
sent := make(chan struct{})
go func() {
defer GinkgoRecover()
q.Send(getPacket([]byte("raboof")))
close(sent)
}()
Consistently(sent).ShouldNot(BeClosed())
done := make(chan struct{})
go func() {
defer GinkgoRecover()
q.Run()
close(done)
}()
Eventually(c.written).Should(Receive(Equal([]byte("foobar"))))
Eventually(c.written).Should(Receive(Equal([]byte("raboof"))))
q.Close()
Eventually(done).Should(BeClosed())
})
})