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

Method TestClientInvalidStreamID

test/end2end_test.go:4558–4580  ·  view source on GitHub ↗

Tests gRPC server's behavior when a gRPC client sends a frame with an invalid streamID. Per [HTTP/2 spec]: Streams initiated by a client MUST use odd-numbered stream identifiers. This test sets up a test server and sends a header frame with stream ID of 2. The test asserts that a subsequent read on

(t *testing.T)

Source from the content-addressed store, hash-verified

4556//
4557// [HTTP/2 spec]: https://httpwg.org/specs/rfc7540.html#StreamIdentifiers
4558func (s) TestClientInvalidStreamID(t *testing.T) {
4559 lis, err := net.Listen("tcp", "localhost:0")
4560 if err != nil {
4561 t.Fatalf("Failed to listen: %v", err)
4562 }
4563 defer lis.Close()
4564 s := grpc.NewServer()
4565 defer s.Stop()
4566 go s.Serve(lis)
4567
4568 conn, err := net.DialTimeout("tcp", lis.Addr().String(), defaultTestTimeout)
4569 if err != nil {
4570 t.Fatalf("Failed to dial: %v", err)
4571 }
4572 st := newServerTesterFromConn(t, conn)
4573 st.greet()
4574 st.writeHeadersGRPC(2, "/grpc.testing.TestService/StreamingInputCall", true)
4575 goAwayFrame := st.wantGoAway(http2.ErrCodeProtocol)
4576 want := "received an illegal stream id: 2."
4577 if got := string(goAwayFrame.DebugData()); !strings.Contains(got, want) {
4578 t.Fatalf(" Received: %v, Expected error message to contain: %v.", got, want)
4579 }
4580}
4581
4582// Tests that a gRPC server transport does not deadlock when it receives a zero
4583// second deadline, and properly returns a deadline exceeded error immediately.

Callers

nothing calls this directly

Calls 11

NewServerFunction · 0.92
newServerTesterFromConnFunction · 0.85
writeHeadersGRPCMethod · 0.80
wantGoAwayMethod · 0.80
FatalfMethod · 0.65
CloseMethod · 0.65
StopMethod · 0.65
ServeMethod · 0.65
StringMethod · 0.65
AddrMethod · 0.45
greetMethod · 0.45

Tested by

no test coverage detected