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

Function TestConnectionWaitReadHalfPacket

connection_test.go:216–248  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

214}
215
216func TestConnectionWaitReadHalfPacket(t *testing.T) {
217 r, w := GetSysFdPairs()
218 rconn := &connection{}
219 rconn.init(&netFD{fd: r}, nil)
220 size := pagesize * 2
221 msg := make([]byte, size)
222
223 // write half packet
224 syscall.Write(w, msg[:size/2])
225 // wait poller reads buffer
226 for rconn.inputBuffer.Len() <= 0 {
227 runtime.Gosched()
228 }
229
230 // wait read full packet
231 var wg sync.WaitGroup
232 wg.Add(1)
233 go func() {
234 defer wg.Done()
235 buf, err := rconn.Reader().Next(size)
236 Equal(t, atomic.LoadInt64(&rconn.waitReadSize), int64(0))
237 MustNil(t, err)
238 Equal(t, len(buf), size)
239 }()
240
241 // write left half packet
242 for atomic.LoadInt64(&rconn.waitReadSize) <= 0 {
243 runtime.Gosched()
244 }
245 Equal(t, atomic.LoadInt64(&rconn.waitReadSize), int64(size))
246 syscall.Write(w, msg[size/2:])
247 wg.Wait()
248}
249
250func TestReadTimer(t *testing.T) {
251 read := time.NewTimer(time.Second)

Callers

nothing calls this directly

Calls 10

initMethod · 0.95
ReaderMethod · 0.95
GetSysFdPairsFunction · 0.85
AddMethod · 0.80
LenMethod · 0.65
NextMethod · 0.65
WaitMethod · 0.65
EqualFunction · 0.50
MustNilFunction · 0.50
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…