forked from quic-go/quic-go
use a mock connection in the send queue tests
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
package quic
|
||||
|
||||
import (
|
||||
"github.com/golang/mock/gomock"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Send Queue", func() {
|
||||
var q *sendQueue
|
||||
var c *mockConnection
|
||||
var c *MockConnection
|
||||
|
||||
BeforeEach(func() {
|
||||
c = newMockConnection()
|
||||
c = NewMockConnection(mockCtrl)
|
||||
q = newSendQueue(c)
|
||||
})
|
||||
|
||||
@@ -25,8 +26,11 @@ var _ = Describe("Send Queue", func() {
|
||||
}
|
||||
|
||||
It("sends a packet", func() {
|
||||
q.Send(getPacket([]byte("foobar")))
|
||||
p := getPacket([]byte("foobar"))
|
||||
q.Send(p)
|
||||
|
||||
written := make(chan struct{})
|
||||
c.EXPECT().Write(p.raw).Do(func([]byte) { close(written) })
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
@@ -34,7 +38,7 @@ var _ = Describe("Send Queue", func() {
|
||||
close(done)
|
||||
}()
|
||||
|
||||
Eventually(c.written).Should(Receive(Equal([]byte("foobar"))))
|
||||
Eventually(written).Should(BeClosed())
|
||||
q.Close()
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
@@ -42,6 +46,9 @@ var _ = Describe("Send Queue", func() {
|
||||
It("blocks sending when too many packets are queued", func() {
|
||||
q.Send(getPacket([]byte("foobar")))
|
||||
|
||||
written := make(chan []byte, 2)
|
||||
c.EXPECT().Write(gomock.Any()).Do(func(p []byte) { written <- p }).Times(2)
|
||||
|
||||
sent := make(chan struct{})
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
@@ -58,8 +65,8 @@ var _ = Describe("Send Queue", func() {
|
||||
close(done)
|
||||
}()
|
||||
|
||||
Eventually(c.written).Should(Receive(Equal([]byte("foobar"))))
|
||||
Eventually(c.written).Should(Receive(Equal([]byte("raboof"))))
|
||||
Eventually(written).Should(Receive(Equal([]byte("foobar"))))
|
||||
Eventually(written).Should(Receive(Equal([]byte("raboof"))))
|
||||
q.Close()
|
||||
Eventually(done).Should(BeClosed())
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user