MCPcopy
hub / github.com/grpc/grpc-go / handleStreamPingPong

Method handleStreamPingPong

internal/transport/transport_test.go:157–182  ·  view source on GitHub ↗
(t *testing.T, s *ServerStream)

Source from the content-addressed store, hash-verified

155}
156
157func (h *testStreamHandler) handleStreamPingPong(t *testing.T, s *ServerStream) {
158 header := make([]byte, 5)
159 for {
160 if _, err := s.readTo(header); err != nil {
161 if err == io.EOF {
162 s.WriteStatus(status.New(codes.OK, ""))
163 return
164 }
165 t.Errorf("Error on server while reading data header: %v", err)
166 s.WriteStatus(status.New(codes.Internal, "panic"))
167 return
168 }
169 sz := binary.BigEndian.Uint32(header[1:])
170 msg := make([]byte, int(sz))
171 if _, err := s.readTo(msg); err != nil {
172 t.Errorf("Error on server while reading message: %v", err)
173 s.WriteStatus(status.New(codes.Internal, "panic"))
174 return
175 }
176 buf := make([]byte, sz+5)
177 buf[0] = byte(0)
178 binary.BigEndian.PutUint32(buf[1:], uint32(sz))
179 copy(buf[5:], msg)
180 s.Write(nil, newBufferSlice(buf), &WriteOptions{})
181 }
182}
183
184func (h *testStreamHandler) handleStreamMisbehave(t *testing.T, s *ServerStream) {
185 conn, ok := s.st.(*http2Server)

Callers 1

startMethod · 0.95

Calls 6

NewFunction · 0.92
newBufferSliceFunction · 0.85
readToMethod · 0.80
WriteStatusMethod · 0.80
ErrorfMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected