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

Function TestConnectionRead

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

Source from the content-addressed store, hash-verified

122}
123
124func TestConnectionRead(t *testing.T) {
125 r, w := GetSysFdPairs()
126 rconn, wconn := &connection{}, &connection{}
127 err := rconn.init(&netFD{fd: r}, nil)
128 MustNil(t, err)
129 err = wconn.init(&netFD{fd: w}, nil)
130 MustNil(t, err)
131
132 size := 256
133 cycleTime := 1000
134 msg := make([]byte, size)
135 var wg sync.WaitGroup
136 wg.Add(1)
137 go func() {
138 defer wg.Done()
139 for i := 0; i < cycleTime; i++ {
140 buf, err := rconn.Reader().Next(size)
141 MustNil(t, err)
142 Equal(t, len(buf), size)
143 rconn.Reader().Release()
144 }
145 }()
146 for i := 0; i < cycleTime; i++ {
147 n, err := wconn.Write(msg)
148 MustNil(t, err)
149 Equal(t, n, len(msg))
150 }
151 wg.Wait()
152 rconn.Close()
153}
154
155// TestConnectionIOReader tests the io.Reader Read method which uses readCopy internally.
156// Verifies that Read after Peek preserves exposed buffer until Release.

Callers

nothing calls this directly

Calls 11

initMethod · 0.95
ReaderMethod · 0.95
WriteMethod · 0.95
CloseMethod · 0.95
GetSysFdPairsFunction · 0.85
AddMethod · 0.80
NextMethod · 0.65
ReleaseMethod · 0.65
WaitMethod · 0.65
MustNilFunction · 0.50
EqualFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…