MCPcopy Create free account
hub / github.com/cloudwego/netpoll / TestLinkBufferIndexByte

Function TestLinkBufferIndexByte

nocopy_linkbuffer_test.go:766–797  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

764}
765
766func TestLinkBufferIndexByte(t *testing.T) {
767 // clean & new
768 LinkBufferCap = 128
769 loopSize := 1000
770 trigger := make(chan struct{}, 16)
771
772 lb := NewLinkBuffer()
773 empty := make([]byte, 1002)
774 go func() {
775 for i := 0; i < loopSize; i++ {
776 buf, err := lb.Malloc(1002)
777 // need clear buffer
778 copy(buf, empty)
779 buf[500] = '\n'
780 buf[1001] = '\n'
781 MustNil(t, err)
782 lb.Flush()
783 trigger <- struct{}{}
784 }
785 }()
786
787 for i := 0; i < loopSize; i++ {
788 <-trigger
789 last := i * 1002
790 n := lb.indexByte('\n', 0+last)
791 Equal(t, n, 500+last)
792 n = lb.indexByte('\n', 500+last)
793 Equal(t, n, 500+last)
794 n = lb.indexByte('\n', 501+last)
795 Equal(t, n, 1001+last)
796 }
797}
798
799func TestLinkBufferPeekOutOfMemory(t *testing.T) {
800 bufCap := 1024 * 8

Callers

nothing calls this directly

Calls 6

NewLinkBufferFunction · 0.85
MallocMethod · 0.65
FlushMethod · 0.65
MustNilFunction · 0.50
EqualFunction · 0.50
indexByteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…