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

Function TestConnectionIOReader

connection_test.go:157–194  ·  view source on GitHub ↗

TestConnectionIOReader tests the io.Reader Read method which uses readCopy internally. Verifies that Read after Peek preserves exposed buffer until Release.

(t *testing.T)

Source from the content-addressed store, hash-verified

155// TestConnectionIOReader tests the io.Reader Read method which uses readCopy internally.
156// Verifies that Read after Peek preserves exposed buffer until Release.
157func TestConnectionIOReader(t *testing.T) {
158 r, w := GetSysFdPairs()
159 rconn := &connection{}
160 rconn.init(&netFD{fd: r}, nil)
161
162 msg := make([]byte, 64)
163 for i := range msg {
164 msg[i] = byte(i)
165 }
166 var wg sync.WaitGroup
167 wg.Add(1)
168 go func() {
169 defer wg.Done()
170 // Peek exposes the underlying buffer
171 pk, err := rconn.Peek(16)
172 MustNil(t, err)
173 Equal(t, len(pk), 16)
174
175 // Read copies without exposing
176 buf := make([]byte, 64)
177 n, err := rconn.Read(buf)
178 MustNil(t, err)
179 Equal(t, n, 64)
180 for i := 0; i < 64; i++ {
181 Equal(t, buf[i], byte(i))
182 }
183
184 // Peek data still valid before Release
185 for i := 0; i < 16; i++ {
186 Equal(t, pk[i], byte(i))
187 }
188 rconn.Release()
189 }()
190 syscall.Write(w, msg)
191 wg.Wait()
192 rconn.Close()
193 syscall.Close(w)
194}
195
196func TestConnectionReadAfterClosed(t *testing.T) {
197 r, w := GetSysFdPairs()

Callers

nothing calls this directly

Calls 12

initMethod · 0.95
PeekMethod · 0.95
ReadMethod · 0.95
ReleaseMethod · 0.95
CloseMethod · 0.95
GetSysFdPairsFunction · 0.85
AddMethod · 0.80
WaitMethod · 0.65
CloseMethod · 0.65
MustNilFunction · 0.50
EqualFunction · 0.50
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…