buffer_pool_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package quic
  2. import (
  3. "github.com/lucas-clemente/quic-go/internal/protocol"
  4. . "github.com/onsi/ginkgo"
  5. . "github.com/onsi/gomega"
  6. )
  7. var _ = Describe("Buffer Pool", func() {
  8. It("returns buffers of cap", func() {
  9. buf := getPacketBuffer()
  10. Expect(buf.Slice).To(HaveCap(int(protocol.MaxReceivePacketSize)))
  11. })
  12. It("releases buffers", func() {
  13. buf := getPacketBuffer()
  14. buf.Release()
  15. })
  16. It("panics if wrong-sized buffers are passed", func() {
  17. buf := getPacketBuffer()
  18. buf.Slice = make([]byte, 10)
  19. Expect(func() { buf.Release() }).To(Panic())
  20. })
  21. It("panics if it is released twice", func() {
  22. buf := getPacketBuffer()
  23. buf.Release()
  24. Expect(func() { buf.Release() }).To(Panic())
  25. })
  26. It("panics if it is decremented too many times", func() {
  27. buf := getPacketBuffer()
  28. buf.Decrement()
  29. Expect(func() { buf.Decrement() }).To(Panic())
  30. })
  31. It("waits until all parts have been released", func() {
  32. buf := getPacketBuffer()
  33. buf.Split()
  34. buf.Split()
  35. // now we have 3 parts
  36. buf.Decrement()
  37. buf.Decrement()
  38. buf.Decrement()
  39. Expect(func() { buf.Decrement() }).To(Panic())
  40. })
  41. })