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

Method TestClientSendsRSTStream_InTrailers

internal/transport/transport_test.go:3744–3783  ·  view source on GitHub ↗

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

(t *testing.T)

Source from the content-addressed store, hash-verified

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.
3744func (s) TestClientSendsRSTStream_InTrailers(t *testing.T) {
3745 serverFrames := func(t *testing.T, framer *http2.Framer, streamID uint32) {
3746 var buf bytes.Buffer
3747 henc := hpack.NewEncoder(&buf)
3748 henc.WriteField(hpack.HeaderField{Name: "content-type", Value: "application/grpc"})
3749 if err := framer.WriteHeaders(http2.HeadersFrameParam{
3750 StreamID: streamID,
3751 BlockFragment: buf.Bytes(),
3752 EndHeaders: true,
3753 EndStream: false,
3754 }); err != nil {
3755 t.Errorf("Server failed to write headers: %v", err)
3756 }
3757 if err := framer.WriteData(streamID, false, expectedResponse); err != nil {
3758 t.Errorf("Server failed to write data: %v", err)
3759 }
3760 buf.Reset()
3761 henc = hpack.NewEncoder(&buf)
3762 henc.WriteField(hpack.HeaderField{Name: "grpc-status", Value: "0"})
3763 if err := framer.WriteHeaders(http2.HeadersFrameParam{
3764 StreamID: streamID,
3765 BlockFragment: buf.Bytes(),
3766 EndHeaders: true,
3767 EndStream: true,
3768 }); err != nil {
3769 t.Errorf("Server failed to write trailers: %v", err)
3770 }
3771 }
3772
3773 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
3774 defer cancel()
3775 stream, waitForServer := setupRSTStreamOnEOSTest(ctx, t, serverFrames)
3776 defer waitForServer()
3777
3778 // Wait for the stream to be closed.
3779 <-stream.Done()
3780 if code := stream.Status().Code(); code != codes.OK {
3781 t.Fatalf("stream.Status().Code() got %s, want %s", code, codes.OK)
3782 }
3783}
3784
3785// Tests the scenario where the server sets the END_STREAM flag in one of its
3786// DATA frames (before sending trailers), causing the client to send a

Callers

nothing calls this directly

Calls 8

ResetMethod · 0.95
setupRSTStreamOnEOSTestFunction · 0.85
CodeMethod · 0.80
StatusMethod · 0.80
BytesMethod · 0.65
ErrorfMethod · 0.65
FatalfMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected