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

Function TestMallocAck

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

Source from the content-addressed store, hash-verified

844}
845
846func TestMallocAck(t *testing.T) {
847 sLen := 1024 * 7
848 buf1 := []byte{1, 2, 3, 4}
849 buf2 := []byte{5, 6, 7, 8}
850 lb := NewLinkBuffer(0)
851
852 buf, err := lb.Malloc(4 + sLen)
853 MustNil(t, err)
854 copy(buf[:4], buf1)
855 s := make([]byte, sLen)
856 err = lb.WriteDirect(s, sLen)
857 MustNil(t, err)
858
859 err = lb.MallocAck(4 + sLen)
860 MustNil(t, err)
861 lb.Flush()
862
863 buf, err = lb.Malloc(4)
864 MustNil(t, err)
865 copy(buf[:4], buf2)
866 lb.Flush()
867
868 buf, err = lb.Next(8 + sLen)
869 MustNil(t, err)
870
871 MustTrue(t, reflect.DeepEqual(buf, append(append(buf1, s...), buf2...)))
872}
873
874func BenchmarkStringToSliceByte(b *testing.B) {
875 b.StopTimer()

Callers

nothing calls this directly

Calls 8

NewLinkBufferFunction · 0.85
MallocMethod · 0.65
WriteDirectMethod · 0.65
MallocAckMethod · 0.65
FlushMethod · 0.65
NextMethod · 0.65
MustNilFunction · 0.50
MustTrueFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…