use a mock ConnectionParametersManager in quic tests

This commit is contained in:
Marten Seemann 2016-12-08 21:50:10 +07:00
parent ba85908fd7
commit c12508c3c9
No known key found for this signature in database
GPG key ID: 3603F40B121FCDEA
5 changed files with 47 additions and 13 deletions

View file

@ -23,7 +23,7 @@ var _ = Describe("Packet packer", func() {
fcm.sendWindowSizes[5] = protocol.MaxByteCount
fcm.sendWindowSizes[7] = protocol.MaxByteCount
cpm := handshake.NewConnectionParamatersManager(protocol.VersionWhatever)
cpm := &mockConnectionParametersManager{}
streamFramer = newStreamFramer(newStreamsMap(nil, cpm), fcm)
packer = &packetPacker{

View file

@ -94,6 +94,7 @@ var _ = Describe("Session", func() {
streamCallbackCalled bool
closeCallbackCalled bool
conn *mockConnection
cpm *mockConnectionParametersManager
)
BeforeEach(func() {
@ -118,6 +119,9 @@ var _ = Describe("Session", func() {
Expect(err).NotTo(HaveOccurred())
session = pSession.(*Session)
Expect(session.streamsMap.NumberOfStreams()).To(Equal(1)) // Crypto stream
cpm = &mockConnectionParametersManager{idleTime: 60 * time.Second}
session.connectionParameters = cpm
})
Context("when handling stream frames", func() {
@ -765,9 +769,7 @@ var _ = Describe("Session", func() {
It("does not use ICSL before handshake", func(done Done) {
session.lastNetworkActivityTime = time.Now().Add(-time.Minute)
session.connectionParameters.SetFromMap(map[handshake.Tag][]byte{
handshake.TagICSL: {0xff, 0xff, 0xff, 0xff},
})
cpm.idleTime = 99999 * time.Second
session.packer.connectionParameters = session.connectionParameters
session.run() // Would normally not return
Expect(conn.written[0]).To(ContainSubstring("No recent network activity."))
@ -778,9 +780,7 @@ var _ = Describe("Session", func() {
// session.lastNetworkActivityTime = time.Now().Add(-time.Minute)
*(*bool)(unsafe.Pointer(reflect.ValueOf(session.cryptoSetup).Elem().FieldByName("receivedForwardSecurePacket").UnsafeAddr())) = true
*(*crypto.AEAD)(unsafe.Pointer(reflect.ValueOf(session.cryptoSetup).Elem().FieldByName("forwardSecureAEAD").UnsafeAddr())) = &crypto.NullAEAD{}
session.connectionParameters.SetFromMap(map[handshake.Tag][]byte{
handshake.TagICSL: {0, 0, 0, 0},
})
cpm.idleTime = 0 * time.Millisecond
session.packer.connectionParameters = session.connectionParameters
session.run() // Would normally not return
Expect(conn.written[0]).To(ContainSubstring("No recent network activity."))

View file

@ -4,7 +4,6 @@ import (
"bytes"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/handshake"
"github.com/lucas-clemente/quic-go/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -32,7 +31,7 @@ var _ = Describe("Stream Framer", func() {
stream1 = &stream{streamID: 10}
stream2 = &stream{streamID: 11}
streamsMap = newStreamsMap(nil, handshake.NewConnectionParamatersManager(protocol.VersionWhatever))
streamsMap = newStreamsMap(nil, &mockConnectionParametersManager{})
streamsMap.putStream(stream1)
streamsMap.putStream(stream2)

View file

@ -8,7 +8,6 @@ import (
"github.com/lucas-clemente/quic-go/congestion"
"github.com/lucas-clemente/quic-go/flowcontrol"
"github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/handshake"
"github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/utils"
. "github.com/onsi/ginkgo"
@ -110,7 +109,7 @@ var _ = Describe("Stream", func() {
BeforeEach(func() {
onDataCalled = false
var streamID protocol.StreamID = 1337
cpm := handshake.NewConnectionParamatersManager(protocol.VersionWhatever)
cpm := &mockConnectionParametersManager{}
flowControlManager := flowcontrol.NewFlowControlManager(cpm, &congestion.RTTStats{})
flowControlManager.NewStream(streamID, true)
str, _ = newStream(streamID, onData, flowControlManager)

View file

@ -2,6 +2,8 @@ package quic
import (
"errors"
"math"
"time"
"github.com/lucas-clemente/quic-go/handshake"
"github.com/lucas-clemente/quic-go/protocol"
@ -10,6 +12,38 @@ import (
. "github.com/onsi/gomega"
)
type mockConnectionParametersManager struct {
maxIncomingStreams uint32
idleTime time.Duration
}
func (m *mockConnectionParametersManager) SetFromMap(map[handshake.Tag][]byte) error {
panic("not implemented")
}
func (m *mockConnectionParametersManager) GetSHLOMap() map[handshake.Tag][]byte {
panic("not implemented")
}
func (m *mockConnectionParametersManager) GetSendStreamFlowControlWindow() protocol.ByteCount {
return math.MaxUint64
}
func (m *mockConnectionParametersManager) GetSendConnectionFlowControlWindow() protocol.ByteCount {
return math.MaxUint64
}
func (m *mockConnectionParametersManager) GetReceiveStreamFlowControlWindow() protocol.ByteCount {
return math.MaxUint64
}
func (m *mockConnectionParametersManager) GetReceiveConnectionFlowControlWindow() protocol.ByteCount {
return math.MaxUint64
}
func (m *mockConnectionParametersManager) GetMaxOutgoingStreams() uint32 { panic("not implemented") }
func (m *mockConnectionParametersManager) GetMaxIncomingStreams() uint32 { return m.maxIncomingStreams }
func (m *mockConnectionParametersManager) GetIdleConnectionStateLifetime() time.Duration {
return m.idleTime
}
func (m *mockConnectionParametersManager) TruncateConnectionID() bool { return false }
var _ handshake.ConnectionParametersManager = &mockConnectionParametersManager{}
var _ = Describe("Streams Map", func() {
var (
cpm handshake.ConnectionParametersManager
@ -17,7 +51,9 @@ var _ = Describe("Streams Map", func() {
)
BeforeEach(func() {
cpm = handshake.NewConnectionParamatersManager(protocol.VersionWhatever)
cpm = &mockConnectionParametersManager{
maxIncomingStreams: 75,
}
m = newStreamsMap(nil, cpm)
})
@ -73,7 +109,7 @@ var _ = Describe("Streams Map", func() {
_, err := m.GetOrOpenStream(protocol.StreamID(i*2 + 1))
Expect(err).NotTo(HaveOccurred())
}
_, err := m.GetOrOpenStream(protocol.StreamID(maxNumStreams))
_, err := m.GetOrOpenStream(protocol.StreamID(2*maxNumStreams + 2))
Expect(err).To(MatchError(qerr.TooManyOpenStreams))
})