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

Method TestClientSendsRSTStream_InHeaders

internal/transport/transport_test.go:3711–3740  ·  view source on GitHub ↗

Tests the scenario where the server sets the END_STREAM flag in the HEADERS frame and verifies that the client responds with a RST stream.

(t *testing.T)

Source from the content-addressed store, hash-verified

3709// Tests the scenario where the server sets the END_STREAM flag in the HEADERS
3710// frame and verifies that the client responds with a RST stream.
3711func (s) TestClientSendsRSTStream_InHeaders(t *testing.T) {
3712 serverFrames := func(t *testing.T, framer *http2.Framer, streamID uint32) {
3713 var buf bytes.Buffer
3714 henc := hpack.NewEncoder(&buf)
3715 henc.WriteField(hpack.HeaderField{Name: "content-type", Value: "application/grpc"})
3716 if err := framer.WriteHeaders(http2.HeadersFrameParam{
3717 StreamID: streamID,
3718 BlockFragment: buf.Bytes(),
3719 EndHeaders: true,
3720 EndStream: true,
3721 }); err != nil {
3722 t.Errorf("Server failed to write headers: %v", err)
3723 }
3724 }
3725
3726 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
3727 defer cancel()
3728 stream, waitForServer := setupRSTStreamOnEOSTest(ctx, t, serverFrames)
3729 defer waitForServer()
3730
3731 if _, err := stream.readTo(make([]byte, 1)); !errors.Is(err, io.EOF) {
3732 t.Fatalf("stream.readTo() got %v, want %v", err, io.EOF)
3733 }
3734
3735 // Ensure the stream is done before checking status.
3736 <-stream.Done()
3737 if code := stream.Status().Code(); code != codes.Unknown {
3738 t.Fatalf("stream.Status().Code() got %s, want %s", code, codes.Unknown)
3739 }
3740}
3741
3742// Tests the scenario where the server sets the END_STREAM flag in the Trailers
3743// (HEADERS frame) and verifies that the client responds with a RST stream.

Callers

nothing calls this directly

Calls 9

setupRSTStreamOnEOSTestFunction · 0.85
readToMethod · 0.80
IsMethod · 0.80
CodeMethod · 0.80
StatusMethod · 0.80
BytesMethod · 0.65
ErrorfMethod · 0.65
FatalfMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected