add method to get ACK from ReceivedPacketHandler without dequeueing it

This commit is contained in:
Marten Seemann 2016-05-13 15:55:56 +07:00
parent f8dc78967a
commit c0c7be16e3
4 changed files with 69 additions and 14 deletions

View file

@ -249,7 +249,7 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(protocol.PacketNumber(2), true)
Expect(err).ToNot(HaveOccurred())
ack, err := handler.DequeueAckFrame()
ack, err := handler.GetAckFrame(true)
Expect(err).ToNot(HaveOccurred())
Expect(ack.LargestObserved).To(Equal(protocol.PacketNumber(2)))
Expect(ack.Entropy).To(Equal(byte(entropy)))
@ -263,7 +263,7 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(protocol.PacketNumber(4), true)
Expect(err).ToNot(HaveOccurred())
ack, err := handler.DequeueAckFrame()
ack, err := handler.GetAckFrame(true)
Expect(err).ToNot(HaveOccurred())
Expect(ack.LargestObserved).To(Equal(protocol.PacketNumber(4)))
Expect(ack.Entropy).To(Equal(byte(entropy)))
@ -275,19 +275,66 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(protocol.PacketNumber(2), false)
Expect(err).ToNot(HaveOccurred())
Expect(handler.DequeueAckFrame()).ToNot(BeNil())
Expect(handler.DequeueAckFrame()).To(BeNil())
ack, err := handler.GetAckFrame(true)
Expect(err).ToNot(HaveOccurred())
Expect(ack).ToNot(BeNil())
ack, err = handler.GetAckFrame(true)
Expect(err).ToNot(HaveOccurred())
Expect(ack).To(BeNil())
})
It("generates an ACK when an out-of-order packet arrives", func() {
It("does not dequeue an ACK frame if told so", func() {
err := handler.ReceivedPacket(protocol.PacketNumber(2), false)
Expect(err).ToNot(HaveOccurred())
ack, err := handler.GetAckFrame(false)
Expect(err).ToNot(HaveOccurred())
Expect(ack).ToNot(BeNil())
ack, err = handler.GetAckFrame(false)
Expect(err).ToNot(HaveOccurred())
Expect(ack).ToNot(BeNil())
ack, err = handler.GetAckFrame(false)
Expect(err).ToNot(HaveOccurred())
Expect(ack).ToNot(BeNil())
})
It("returns a cached ACK frame if the ACK was not dequeued", func() {
err := handler.ReceivedPacket(protocol.PacketNumber(2), false)
Expect(err).ToNot(HaveOccurred())
ack, err := handler.GetAckFrame(false)
Expect(err).ToNot(HaveOccurred())
Expect(ack).ToNot(BeNil())
ack2, err := handler.GetAckFrame(false)
Expect(err).ToNot(HaveOccurred())
Expect(ack2).ToNot(BeNil())
Expect(&ack).To(Equal(&ack2))
})
It("generates a new ACK (and deletes the cached one) when a new packet arrives", func() {
err := handler.ReceivedPacket(protocol.PacketNumber(1), false)
Expect(err).ToNot(HaveOccurred())
ack, _ := handler.GetAckFrame(true)
Expect(ack).ToNot(BeNil())
Expect(ack.LargestObserved).To(Equal(protocol.PacketNumber(1)))
err = handler.ReceivedPacket(protocol.PacketNumber(3), false)
Expect(err).ToNot(HaveOccurred())
ack, _ = handler.GetAckFrame(true)
Expect(ack).ToNot(BeNil())
Expect(ack.LargestObserved).To(Equal(protocol.PacketNumber(3)))
})
It("generates a new ACK when an out-of-order packet arrives", func() {
err := handler.ReceivedPacket(protocol.PacketNumber(1), false)
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(protocol.PacketNumber(3), false)
Expect(err).ToNot(HaveOccurred())
Expect(handler.DequeueAckFrame()).ToNot(BeNil())
ack, _ := handler.GetAckFrame(true)
Expect(ack).ToNot(BeNil())
Expect(len(ack.NackRanges)).To(Equal(1))
err = handler.ReceivedPacket(protocol.PacketNumber(2), false)
Expect(err).ToNot(HaveOccurred())
Expect(handler.DequeueAckFrame()).ToNot(BeNil())
ack, _ = handler.GetAckFrame(true)
Expect(ack).ToNot(BeNil())
Expect(len(ack.NackRanges)).To(Equal(0))
})
})
})