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

Function TestLinkBufferReadCopy

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

Source from the content-addressed store, hash-verified

541}
542
543func TestLinkBufferReadCopy(t *testing.T) {
544 t.Run("SingleNode", func(t *testing.T) {
545 LinkBufferCap = 128
546 buf := NewLinkBuffer(128)
547 p, _ := buf.Malloc(16)
548 for i := range p {
549 p[i] = byte(i)
550 }
551 buf.Flush()
552
553 dst := make([]byte, 10)
554 n := buf.readCopy(dst)
555 Equal(t, n, 10)
556 for i := 0; i < 10; i++ {
557 Equal(t, dst[i], byte(i))
558 }
559 Equal(t, buf.Len(), 6)
560 // readCopy must not set readExposed
561 MustTrue(t, !buf.read.readExposed())
562 })
563
564 t.Run("MultiNode", func(t *testing.T) {
565 LinkBufferCap = 8
566 buf := NewLinkBuffer(8)
567 p, _ := buf.Malloc(8)
568 for i := range p {
569 p[i] = byte(i)
570 }
571 buf.Flush()
572 p, _ = buf.Malloc(8)
573 for i := range p {
574 p[i] = byte(i + 8)
575 }
576 buf.Flush()
577
578 dst := make([]byte, 16)
579 n := buf.readCopy(dst)
580 Equal(t, n, 16)
581 for i := 0; i < 16; i++ {
582 Equal(t, dst[i], byte(i))
583 }
584 Equal(t, buf.Len(), 0)
585 })
586
587 t.Run("PartialRead", func(t *testing.T) {
588 LinkBufferCap = 128
589 buf := NewLinkBuffer(128)
590 p, _ := buf.Malloc(4)
591 for i := range p {
592 p[i] = byte(i + 1)
593 }
594 buf.Flush()
595
596 // read more than available
597 dst := make([]byte, 16)
598 n := buf.readCopy(dst)
599 Equal(t, n, 4)
600 Equal(t, dst[0], byte(1))

Callers

nothing calls this directly

Calls 11

NewLinkBufferFunction · 0.85
readExposedMethod · 0.80
MallocMethod · 0.65
FlushMethod · 0.65
LenMethod · 0.65
PeekMethod · 0.65
ReleaseMethod · 0.65
EqualFunction · 0.50
MustTrueFunction · 0.50
RunMethod · 0.45
readCopyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…