window_update_queue_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package quic
  2. import (
  3. "github.com/lucas-clemente/quic-go/internal/mocks"
  4. "github.com/lucas-clemente/quic-go/internal/protocol"
  5. "github.com/lucas-clemente/quic-go/internal/wire"
  6. . "github.com/onsi/ginkgo"
  7. . "github.com/onsi/gomega"
  8. )
  9. var _ = Describe("Window Update Queue", func() {
  10. var (
  11. q *windowUpdateQueue
  12. streamGetter *MockStreamGetter
  13. connFC *mocks.MockConnectionFlowController
  14. queuedFrames []wire.Frame
  15. )
  16. BeforeEach(func() {
  17. streamGetter = NewMockStreamGetter(mockCtrl)
  18. connFC = mocks.NewMockConnectionFlowController(mockCtrl)
  19. queuedFrames = queuedFrames[:0]
  20. q = newWindowUpdateQueue(streamGetter, connFC, func(f wire.Frame) {
  21. queuedFrames = append(queuedFrames, f)
  22. })
  23. })
  24. It("adds stream offsets and gets MAX_STREAM_DATA frames", func() {
  25. stream1 := NewMockStreamI(mockCtrl)
  26. stream1.EXPECT().getWindowUpdate().Return(protocol.ByteCount(10))
  27. stream3 := NewMockStreamI(mockCtrl)
  28. stream3.EXPECT().getWindowUpdate().Return(protocol.ByteCount(30))
  29. streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(3)).Return(stream3, nil)
  30. streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(1)).Return(stream1, nil)
  31. q.AddStream(3)
  32. q.AddStream(1)
  33. q.QueueAll()
  34. Expect(queuedFrames).To(ContainElement(&wire.MaxStreamDataFrame{StreamID: 1, ByteOffset: 10}))
  35. Expect(queuedFrames).To(ContainElement(&wire.MaxStreamDataFrame{StreamID: 3, ByteOffset: 30}))
  36. })
  37. It("deletes the entry after getting the MAX_STREAM_DATA frame", func() {
  38. stream10 := NewMockStreamI(mockCtrl)
  39. stream10.EXPECT().getWindowUpdate().Return(protocol.ByteCount(100))
  40. streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(10)).Return(stream10, nil)
  41. q.AddStream(10)
  42. q.QueueAll()
  43. Expect(queuedFrames).To(HaveLen(1))
  44. q.QueueAll()
  45. Expect(queuedFrames).To(HaveLen(1))
  46. })
  47. It("doesn't queue a MAX_STREAM_DATA for a closed stream", func() {
  48. streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(12)).Return(nil, nil)
  49. q.AddStream(12)
  50. q.QueueAll()
  51. Expect(queuedFrames).To(BeEmpty())
  52. })
  53. It("doesn't queue a MAX_STREAM_DATA if the flow controller returns an offset of 0", func() {
  54. stream5 := NewMockStreamI(mockCtrl)
  55. stream5.EXPECT().getWindowUpdate().Return(protocol.ByteCount(0))
  56. streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(5)).Return(stream5, nil)
  57. q.AddStream(5)
  58. q.QueueAll()
  59. Expect(queuedFrames).To(BeEmpty())
  60. })
  61. It("queues MAX_DATA frames", func() {
  62. connFC.EXPECT().GetWindowUpdate().Return(protocol.ByteCount(0x1337))
  63. q.AddConnection()
  64. q.QueueAll()
  65. Expect(queuedFrames).To(Equal([]wire.Frame{
  66. &wire.MaxDataFrame{ByteOffset: 0x1337},
  67. }))
  68. })
  69. It("deduplicates", func() {
  70. stream10 := NewMockStreamI(mockCtrl)
  71. stream10.EXPECT().getWindowUpdate().Return(protocol.ByteCount(200))
  72. streamGetter.EXPECT().GetOrOpenReceiveStream(protocol.StreamID(10)).Return(stream10, nil)
  73. q.AddStream(10)
  74. q.AddStream(10)
  75. q.QueueAll()
  76. Expect(queuedFrames).To(Equal([]wire.Frame{
  77. &wire.MaxStreamDataFrame{StreamID: 10, ByteOffset: 200},
  78. }))
  79. })
  80. })