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

Function TestLinkBufferMultiNode

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

Source from the content-addressed store, hash-verified

198}
199
200func TestLinkBufferMultiNode(t *testing.T) {
201 // clean & new
202 LinkBufferCap = 8
203
204 buf := NewLinkBuffer()
205 Equal(t, buf.Len(), 0)
206 MustTrue(t, buf.IsEmpty())
207 var p []byte
208
209 p, _ = buf.Malloc(15)
210 for i := 0; i < len(p); i++ { // updates p[0] - p[14] to 0 - 14
211 p[i] = byte(i)
212 }
213 Equal(t, len(p), 15)
214 MustTrue(t, buf.read == buf.flush)
215 Equal(t, buf.read.off, 0)
216 Equal(t, buf.read.malloc, 0)
217 Equal(t, buf.write.off, 0)
218 Equal(t, buf.write.malloc, 15)
219 Equal(t, cap(buf.write.buf), 16) // mcache up-aligned to the power of 2
220
221 p, _ = buf.Malloc(7)
222 for i := 0; i < len(p); i++ { // updates p[0] - p[6] to 15 - 21
223 p[i] = byte(i + 15)
224 }
225 Equal(t, len(p), 7)
226 MustTrue(t, buf.read == buf.flush)
227 Equal(t, buf.read.off, 0)
228 Equal(t, buf.read.malloc, 0)
229 Equal(t, buf.write.off, 0)
230 Equal(t, buf.write.malloc, 7)
231 Equal(t, cap(buf.write.buf), LinkBufferCap)
232
233 buf.Flush()
234 MustTrue(t, buf.read != buf.flush)
235 MustTrue(t, buf.flush == buf.write)
236 Equal(t, buf.read.off, 0)
237 Equal(t, len(buf.read.buf), 0)
238 Equal(t, buf.read.next.off, 0)
239 Equal(t, len(buf.read.next.buf), 15)
240 Equal(t, buf.flush.off, 0)
241 Equal(t, buf.flush.malloc, 7)
242 Equal(t, len(buf.flush.buf), 7)
243
244 p, _ = buf.Next(13)
245 Equal(t, len(p), 13)
246 Equal(t, p[0], byte(0))
247 Equal(t, p[12], byte(12))
248 MustTrue(t, buf.read != buf.flush)
249 Equal(t, buf.read.off, 13)
250 Equal(t, buf.read.Len(), 2)
251 Equal(t, buf.read.next.Len(), 7)
252 Equal(t, buf.flush.off, 0)
253 Equal(t, buf.flush.malloc, 7)
254 MustTrue(t, buf.read.readExposed()) // single-node Next
255 MustTrue(t, !buf.flush.readExposed()) // not touched yet
256
257 // Peek

Callers

nothing calls this directly

Calls 14

NewLinkBufferFunction · 0.85
readExposedMethod · 0.80
LenMethod · 0.65
MallocMethod · 0.65
FlushMethod · 0.65
NextMethod · 0.65
PeekMethod · 0.65
MallocAckMethod · 0.65
SkipMethod · 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…