github.com/MerlinKodo/quic-go@v0.39.2/buffer_pool_test.go (about)

     1  package quic
     2  
     3  import (
     4  	"github.com/MerlinKodo/quic-go/internal/protocol"
     5  
     6  	. "github.com/onsi/ginkgo/v2"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  var _ = Describe("Buffer Pool", func() {
    11  	It("returns buffers of cap", func() {
    12  		buf1 := getPacketBuffer()
    13  		Expect(buf1.Data).To(HaveCap(protocol.MaxPacketBufferSize))
    14  		buf2 := getLargePacketBuffer()
    15  		Expect(buf2.Data).To(HaveCap(protocol.MaxLargePacketBufferSize))
    16  	})
    17  
    18  	It("releases buffers", func() {
    19  		buf1 := getPacketBuffer()
    20  		buf1.Release()
    21  		buf2 := getLargePacketBuffer()
    22  		buf2.Release()
    23  	})
    24  
    25  	It("gets the length", func() {
    26  		buf := getPacketBuffer()
    27  		buf.Data = append(buf.Data, []byte("foobar")...)
    28  		Expect(buf.Len()).To(BeEquivalentTo(6))
    29  	})
    30  
    31  	It("panics if wrong-sized buffers are passed", func() {
    32  		buf := getPacketBuffer()
    33  		buf.Data = make([]byte, 10)
    34  		Expect(func() { buf.Release() }).To(Panic())
    35  	})
    36  
    37  	It("panics if it is released twice", func() {
    38  		buf := getPacketBuffer()
    39  		buf.Release()
    40  		Expect(func() { buf.Release() }).To(Panic())
    41  	})
    42  
    43  	It("panics if it is decremented too many times", func() {
    44  		buf := getPacketBuffer()
    45  		buf.Decrement()
    46  		Expect(func() { buf.Decrement() }).To(Panic())
    47  	})
    48  
    49  	It("waits until all parts have been released", func() {
    50  		buf := getPacketBuffer()
    51  		buf.Split()
    52  		buf.Split()
    53  		// now we have 3 parts
    54  		buf.Decrement()
    55  		buf.Decrement()
    56  		buf.Decrement()
    57  		Expect(func() { buf.Decrement() }).To(Panic())
    58  	})
    59  })