mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-05 05:07:36 +03:00
Mock CPM everywhere using gomock
This commit is contained in:
parent
d01f9880be
commit
c02f904479
4 changed files with 23 additions and 53 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/lucas-clemente/quic-go/ackhandler"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"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/qerr"
|
||||
. "github.com/onsi/ginkgo"
|
||||
|
@ -48,12 +49,14 @@ var _ = Describe("Packet packer", func() {
|
|||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
cpm := &mockConnectionParametersManager{}
|
||||
streamFramer = newStreamFramer(newStreamsMap(nil, protocol.PerspectiveServer, cpm), nil)
|
||||
mockCpm := mocks.NewMockConnectionParametersManager(mockCtrl)
|
||||
mockCpm.EXPECT().TruncateConnectionID().Return(false).AnyTimes()
|
||||
|
||||
streamFramer = newStreamFramer(newStreamsMap(nil, protocol.PerspectiveServer, nil), nil)
|
||||
|
||||
packer = &packetPacker{
|
||||
cryptoSetup: &mockCryptoSetup{encLevelSeal: protocol.EncryptionForwardSecure},
|
||||
connectionParameters: cpm,
|
||||
connectionParameters: mockCpm,
|
||||
connectionID: 0x1337,
|
||||
packetNumberGenerator: newPacketNumberGenerator(protocol.SkipPacketAveragePeriodLength),
|
||||
streamFramer: streamFramer,
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/lucas-clemente/quic-go/crypto"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"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/protocol"
|
||||
"github.com/lucas-clemente/quic-go/qerr"
|
||||
|
@ -127,7 +128,7 @@ var _ = Describe("Session", func() {
|
|||
sess *session
|
||||
scfg *handshake.ServerConfig
|
||||
mconn *mockConnection
|
||||
cpm *mockConnectionParametersManager
|
||||
mockCpm *mocks.MockConnectionParametersManager
|
||||
cryptoSetup *mockCryptoSetup
|
||||
handshakeChan <-chan handshakeEvent
|
||||
aeadChanged chan<- protocol.EncryptionLevel
|
||||
|
@ -172,8 +173,9 @@ var _ = Describe("Session", func() {
|
|||
sess = pSess.(*session)
|
||||
Expect(sess.streamsMap.openStreams).To(HaveLen(1)) // Crypto stream
|
||||
|
||||
cpm = &mockConnectionParametersManager{idleTime: 60 * time.Second}
|
||||
sess.connectionParameters = cpm
|
||||
mockCpm = mocks.NewMockConnectionParametersManager(mockCtrl)
|
||||
mockCpm.EXPECT().GetIdleConnectionStateLifetime().Return(time.Minute).AnyTimes()
|
||||
sess.connectionParameters = mockCpm
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
|
@ -1417,8 +1419,11 @@ var _ = Describe("Session", func() {
|
|||
|
||||
It("does not use ICSL before handshake", func(done Done) {
|
||||
sess.lastNetworkActivityTime = time.Now().Add(-time.Minute)
|
||||
cpm.idleTime = 99999 * time.Second
|
||||
sess.packer.connectionParameters = sess.connectionParameters
|
||||
mockCpm = mocks.NewMockConnectionParametersManager(mockCtrl)
|
||||
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
|
||||
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.NetworkIdleTimeout))
|
||||
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) {
|
||||
close(aeadChanged)
|
||||
cpm.idleTime = 0 * time.Millisecond
|
||||
sess.packer.connectionParameters = sess.connectionParameters
|
||||
mockCpm = mocks.NewMockConnectionParametersManager(mockCtrl)
|
||||
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
|
||||
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.NetworkIdleTimeout))
|
||||
Expect(mconn.written[0]).To(ContainSubstring("No recent network activity."))
|
||||
|
|
|
@ -37,7 +37,7 @@ var _ = Describe("Stream Framer", func() {
|
|||
stream1 = &stream{streamID: id1}
|
||||
stream2 = &stream{streamID: id2}
|
||||
|
||||
streamsMap = newStreamsMap(nil, protocol.PerspectiveServer, &mockConnectionParametersManager{})
|
||||
streamsMap = newStreamsMap(nil, protocol.PerspectiveServer, nil)
|
||||
streamsMap.putStream(stream1)
|
||||
streamsMap.putStream(stream2)
|
||||
|
||||
|
|
|
@ -2,10 +2,7 @@ package quic
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"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/qerr"
|
||||
|
@ -13,45 +10,6 @@ import (
|
|||
. "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() {
|
||||
const (
|
||||
maxIncomingStreams = 75
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue