Mock CPM everywhere using gomock

This commit is contained in:
Lucas Clemente 2017-06-09 12:38:07 +02:00
parent d01f9880be
commit c02f904479
4 changed files with 23 additions and 53 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/lucas-clemente/quic-go/ackhandler" "github.com/lucas-clemente/quic-go/ackhandler"
"github.com/lucas-clemente/quic-go/frames" "github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/handshake" "github.com/lucas-clemente/quic-go/handshake"
"github.com/lucas-clemente/quic-go/internal/mocks"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/qerr" "github.com/lucas-clemente/quic-go/qerr"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
@ -48,12 +49,14 @@ var _ = Describe("Packet packer", func() {
) )
BeforeEach(func() { BeforeEach(func() {
cpm := &mockConnectionParametersManager{} mockCpm := mocks.NewMockConnectionParametersManager(mockCtrl)
streamFramer = newStreamFramer(newStreamsMap(nil, protocol.PerspectiveServer, cpm), nil) mockCpm.EXPECT().TruncateConnectionID().Return(false).AnyTimes()
streamFramer = newStreamFramer(newStreamsMap(nil, protocol.PerspectiveServer, nil), nil)
packer = &packetPacker{ packer = &packetPacker{
cryptoSetup: &mockCryptoSetup{encLevelSeal: protocol.EncryptionForwardSecure}, cryptoSetup: &mockCryptoSetup{encLevelSeal: protocol.EncryptionForwardSecure},
connectionParameters: cpm, connectionParameters: mockCpm,
connectionID: 0x1337, connectionID: 0x1337,
packetNumberGenerator: newPacketNumberGenerator(protocol.SkipPacketAveragePeriodLength), packetNumberGenerator: newPacketNumberGenerator(protocol.SkipPacketAveragePeriodLength),
streamFramer: streamFramer, streamFramer: streamFramer,

View file

@ -17,6 +17,7 @@ import (
"github.com/lucas-clemente/quic-go/crypto" "github.com/lucas-clemente/quic-go/crypto"
"github.com/lucas-clemente/quic-go/frames" "github.com/lucas-clemente/quic-go/frames"
"github.com/lucas-clemente/quic-go/handshake" "github.com/lucas-clemente/quic-go/handshake"
"github.com/lucas-clemente/quic-go/internal/mocks"
"github.com/lucas-clemente/quic-go/internal/mocks/mocks_fc" "github.com/lucas-clemente/quic-go/internal/mocks/mocks_fc"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/qerr" "github.com/lucas-clemente/quic-go/qerr"
@ -127,7 +128,7 @@ var _ = Describe("Session", func() {
sess *session sess *session
scfg *handshake.ServerConfig scfg *handshake.ServerConfig
mconn *mockConnection mconn *mockConnection
cpm *mockConnectionParametersManager mockCpm *mocks.MockConnectionParametersManager
cryptoSetup *mockCryptoSetup cryptoSetup *mockCryptoSetup
handshakeChan <-chan handshakeEvent handshakeChan <-chan handshakeEvent
aeadChanged chan<- protocol.EncryptionLevel aeadChanged chan<- protocol.EncryptionLevel
@ -172,8 +173,9 @@ var _ = Describe("Session", func() {
sess = pSess.(*session) sess = pSess.(*session)
Expect(sess.streamsMap.openStreams).To(HaveLen(1)) // Crypto stream Expect(sess.streamsMap.openStreams).To(HaveLen(1)) // Crypto stream
cpm = &mockConnectionParametersManager{idleTime: 60 * time.Second} mockCpm = mocks.NewMockConnectionParametersManager(mockCtrl)
sess.connectionParameters = cpm mockCpm.EXPECT().GetIdleConnectionStateLifetime().Return(time.Minute).AnyTimes()
sess.connectionParameters = mockCpm
}) })
AfterEach(func() { AfterEach(func() {
@ -1417,8 +1419,11 @@ var _ = Describe("Session", func() {
It("does not use ICSL before handshake", func(done Done) { It("does not use ICSL before handshake", func(done Done) {
sess.lastNetworkActivityTime = time.Now().Add(-time.Minute) sess.lastNetworkActivityTime = time.Now().Add(-time.Minute)
cpm.idleTime = 99999 * time.Second mockCpm = mocks.NewMockConnectionParametersManager(mockCtrl)
sess.packer.connectionParameters = sess.connectionParameters mockCpm.EXPECT().GetIdleConnectionStateLifetime().Return(9999 * time.Second).AnyTimes()
mockCpm.EXPECT().TruncateConnectionID().Return(false).AnyTimes()
sess.connectionParameters = mockCpm
sess.packer.connectionParameters = mockCpm
err := sess.run() // Would normally not return err := sess.run() // Would normally not return
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.NetworkIdleTimeout)) Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.NetworkIdleTimeout))
Expect(mconn.written[0]).To(ContainSubstring("No recent network activity.")) Expect(mconn.written[0]).To(ContainSubstring("No recent network activity."))
@ -1428,8 +1433,12 @@ var _ = Describe("Session", func() {
It("uses ICSL after handshake", func(done Done) { It("uses ICSL after handshake", func(done Done) {
close(aeadChanged) close(aeadChanged)
cpm.idleTime = 0 * time.Millisecond mockCpm = mocks.NewMockConnectionParametersManager(mockCtrl)
sess.packer.connectionParameters = sess.connectionParameters mockCpm.EXPECT().GetIdleConnectionStateLifetime().Return(0 * time.Second)
mockCpm.EXPECT().TruncateConnectionID().Return(false).AnyTimes()
sess.connectionParameters = mockCpm
sess.packer.connectionParameters = mockCpm
mockCpm.EXPECT().GetIdleConnectionStateLifetime().Return(0 * time.Second).AnyTimes()
err := sess.run() // Would normally not return err := sess.run() // Would normally not return
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.NetworkIdleTimeout)) Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.NetworkIdleTimeout))
Expect(mconn.written[0]).To(ContainSubstring("No recent network activity.")) Expect(mconn.written[0]).To(ContainSubstring("No recent network activity."))

View file

@ -37,7 +37,7 @@ var _ = Describe("Stream Framer", func() {
stream1 = &stream{streamID: id1} stream1 = &stream{streamID: id1}
stream2 = &stream{streamID: id2} stream2 = &stream{streamID: id2}
streamsMap = newStreamsMap(nil, protocol.PerspectiveServer, &mockConnectionParametersManager{}) streamsMap = newStreamsMap(nil, protocol.PerspectiveServer, nil)
streamsMap.putStream(stream1) streamsMap.putStream(stream1)
streamsMap.putStream(stream2) streamsMap.putStream(stream2)

View file

@ -2,10 +2,7 @@ package quic
import ( import (
"errors" "errors"
"math"
"time"
"github.com/lucas-clemente/quic-go/handshake"
"github.com/lucas-clemente/quic-go/internal/mocks" "github.com/lucas-clemente/quic-go/internal/mocks"
"github.com/lucas-clemente/quic-go/protocol" "github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/qerr" "github.com/lucas-clemente/quic-go/qerr"
@ -13,45 +10,6 @@ import (
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
type mockConnectionParametersManager struct {
maxIncomingStreams uint32
maxOutgoingStreams uint32
idleTime time.Duration
}
func (m *mockConnectionParametersManager) SetFromMap(map[handshake.Tag][]byte) error {
panic("not implemented")
}
func (m *mockConnectionParametersManager) GetHelloMap() (map[handshake.Tag][]byte, error) {
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) GetMaxReceiveStreamFlowControlWindow() protocol.ByteCount {
return math.MaxUint64
}
func (m *mockConnectionParametersManager) GetReceiveConnectionFlowControlWindow() protocol.ByteCount {
return math.MaxUint64
}
func (m *mockConnectionParametersManager) GetMaxReceiveConnectionFlowControlWindow() protocol.ByteCount {
return math.MaxUint64
}
func (m *mockConnectionParametersManager) GetMaxOutgoingStreams() uint32 { return m.maxOutgoingStreams }
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 _ = Describe("Streams Map", func() {
const ( const (
maxIncomingStreams = 75 maxIncomingStreams = 75