add garbage collector for ReceivedPacketHandler

fixes #7
This commit is contained in:
Marten Seemann 2016-05-20 17:09:47 +07:00
parent 283f75aa98
commit a1ba23aebd
2 changed files with 39 additions and 3 deletions

View file

@ -25,13 +25,13 @@ var _ = Describe("receivedPacketHandler", func() {
It("handles a packet that arrives late", func() {
err := handler.ReceivedPacket(protocol.PacketNumber(1), false)
Expect(err).ToNot(HaveOccurred())
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(1)))
err = handler.ReceivedPacket(protocol.PacketNumber(3), false)
Expect(err).ToNot(HaveOccurred())
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(3)))
err = handler.ReceivedPacket(protocol.PacketNumber(2), false)
Expect(err).ToNot(HaveOccurred())
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(1)))
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(2)))
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(3)))
})
It("rejects packets with packet number 0", func() {
@ -334,4 +334,26 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(ack.NackRanges).To(BeEmpty())
})
})
Context("Garbage Collector", func() {
It("only keeps packets with packet numbers higher than the highestInOrderObserved in packetHistory", func() {
handler.ReceivedPacket(1, true)
handler.ReceivedPacket(2, true)
handler.ReceivedPacket(4, true)
Expect(handler.packetHistory).ToNot(HaveKey(protocol.PacketNumber(1)))
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(2)))
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(4)))
})
It("garbage collects packetHistory after receiving a StopWaiting", func() {
handler.ReceivedPacket(1, true)
handler.ReceivedPacket(2, true)
handler.ReceivedPacket(4, true)
swf := frames.StopWaitingFrame{LeastUnacked: 4}
handler.ReceivedStopWaiting(&swf)
Expect(handler.packetHistory).ToNot(HaveKey(protocol.PacketNumber(1)))
Expect(handler.packetHistory).ToNot(HaveKey(protocol.PacketNumber(2)))
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(4)))
})
})
})