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

Function TestLinkBufferRefer

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

Source from the content-addressed store, hash-verified

329}
330
331func TestLinkBufferRefer(t *testing.T) {
332 // clean & new
333 LinkBufferCap = 8
334
335 wbuf := NewLinkBuffer()
336 wbuf.book(block8k, block8k)
337 wbuf.Malloc(7)
338 wbuf.Flush()
339 Equal(t, wbuf.Len(), block8k+7)
340
341 buf := NewLinkBuffer()
342 var p []byte
343
344 // writev
345 buf.WriteBuffer(wbuf)
346 buf.Flush()
347 Equal(t, buf.Len(), block8k+7)
348
349 p, _ = buf.Next(5)
350 Equal(t, len(p), 5)
351 MustTrue(t, buf.read != buf.flush)
352 Equal(t, buf.read.off, 5)
353 Equal(t, buf.read.Len(), block8k-5)
354 Equal(t, buf.flush.off, 0)
355 Equal(t, buf.flush.malloc, 7)
356 Equal(t, cap(buf.flush.buf), 8)
357 MustTrue(t, buf.read.readExposed()) // single-node Next
358
359 // readv
360 _rbuf, err := buf.Slice(4)
361 rbuf, ok := _rbuf.(*LinkBuffer)
362 MustNil(t, err)
363 MustTrue(t, ok)
364 Equal(t, rbuf.Len(), 4)
365 MustTrue(t, rbuf.read != rbuf.flush)
366 Equal(t, rbuf.read.off, 0)
367 Equal(t, rbuf.read.Len(), 4)
368
369 MustTrue(t, buf.head != buf.read) // Slice will Release
370 MustTrue(t, rbuf.read != buf.read)
371 Equal(t, buf.Len(), block8k-2)
372 MustTrue(t, buf.read != buf.flush)
373 Equal(t, buf.read.off, 9)
374 Equal(t, buf.read.malloc, block8k)
375
376 // release
377 node1 := rbuf.head
378 node2 := buf.head
379 rbuf.Skip(rbuf.Len())
380 err = rbuf.Release()
381 MustNil(t, err)
382 MustTrue(t, rbuf.head != node1)
383 MustTrue(t, buf.head == node2)
384
385 err = buf.Release()
386 MustNil(t, err)
387 MustTrue(t, buf.head != node2)
388 MustTrue(t, buf.head == buf.read)

Callers

nothing calls this directly

Calls 14

NewLinkBufferFunction · 0.85
readExposedMethod · 0.80
MallocMethod · 0.65
FlushMethod · 0.65
LenMethod · 0.65
NextMethod · 0.65
SliceMethod · 0.65
SkipMethod · 0.65
ReleaseMethod · 0.65
EqualFunction · 0.50
MustTrueFunction · 0.50
MustNilFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…