-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gRPC tests for trailers-only (#904)
This mirrors the gRPC-Web test cases that also handle different forms of trailers in responses. These weren't originally included because I didn't think they would work: I thought that the "net/http" server would encode these on the wire in HTTP/2 using a HEADER frame (_without_ END_STREAM flag) followed by an empty DATA frame (with END_STREAM flag). But the gRPC spec (and Google's implementations) require a trailers-only response in HTTP/2 be a single HEADER frame with END_STREAM flag set. However, I was mistaken: the Go "net/http" server does exactly what we need it to. It would only use two frames (i.e. a second, empty DATA frame) if the handler flushes the `http.ResponseWriter` before it returns. So I didn't have to actually touch the reference server for this to work. 🎉
- Loading branch information
Showing
1 changed file
with
132 additions
and
0 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
internal/app/connectconformance/testsuites/data/grpc_client_trailers.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
name: gRPC Trailers | ||
mode: TEST_MODE_CLIENT | ||
relevantProtocols: | ||
- PROTOCOL_GRPC | ||
relevantHttpVersions: | ||
- HTTP_VERSION_2 | ||
relevantCodecs: | ||
- CODEC_PROTO | ||
# These tests verify that a gRPC client can handle both normal responses | ||
# with trailers and trailers-only responses (trailers in headers). | ||
testCases: | ||
# Trailers and status are separate from headers (no other response messages) | ||
- request: | ||
testName: trailers-at-end/expected | ||
streamType: STREAM_TYPE_UNARY | ||
requestMessages: | ||
- "@type": type.googleapis.com/connectrpc.conformance.v1.UnaryRequest | ||
responseDefinition: | ||
rawResponse: | ||
status_code: 200 | ||
headers: | ||
- name: content-type | ||
value: [ "application/grpc" ] | ||
- name: x-custom-header | ||
value: [ "foo" ] | ||
trailers: | ||
- name: grpc-status | ||
value: [ "9" ] | ||
- name: grpc-message | ||
value: [ "error" ] | ||
- name: x-custom-trailer | ||
value: [ "bing" ] | ||
expectedResponse: | ||
responseHeaders: | ||
- name: x-custom-header | ||
value: [ "foo" ] | ||
error: | ||
code: 9 | ||
message: error | ||
responseTrailers: | ||
- name: x-custom-trailer | ||
value: [ "bing" ] | ||
- request: | ||
testName: trailers-at-end/duplicate-metadata | ||
streamType: STREAM_TYPE_UNARY | ||
requestMessages: | ||
- "@type": type.googleapis.com/connectrpc.conformance.v1.UnaryRequest | ||
responseDefinition: | ||
rawResponse: | ||
status_code: 200 | ||
headers: | ||
- name: content-type | ||
value: [ "application/grpc" ] | ||
- name: x-custom-header | ||
value: [ "foo", "bar", "baz" ] | ||
trailers: | ||
- name: grpc-status | ||
value: [ "9" ] | ||
- name: grpc-message | ||
value: [ "error" ] | ||
- name: x-custom-trailer | ||
value: [ "bing", "quuz" ] | ||
expectedResponse: | ||
responseHeaders: | ||
- name: x-custom-header | ||
value: [ "foo", "bar", "baz" ] | ||
error: | ||
code: 9 | ||
message: error | ||
responseTrailers: | ||
- name: x-custom-trailer | ||
value: [ "bing", "quuz" ] | ||
|
||
# Trailers-only responses, where status and trailers are in HTTP headers | ||
- request: | ||
testName: trailers-only/expected | ||
streamType: STREAM_TYPE_UNARY | ||
requestMessages: | ||
- "@type": type.googleapis.com/connectrpc.conformance.v1.UnaryRequest | ||
responseDefinition: | ||
rawResponse: | ||
status_code: 200 | ||
headers: | ||
- name: content-type | ||
value: [ "application/grpc" ] | ||
- name: x-custom-trailer | ||
value: [ "bing" ] | ||
- name: grpc-status | ||
value: [ "9" ] | ||
- name: grpc-message | ||
value: [ "error" ] | ||
# a "magic header" is required to get reference server to emit | ||
# valid HTTP/2 trailers-only frames (must have end-stream flag | ||
# on header frame; no data frame allowed) | ||
- name: x-connect-trailers-only | ||
value: ["1"] | ||
expectedResponse: | ||
error: | ||
code: 9 | ||
message: error | ||
responseTrailers: | ||
- name: x-custom-trailer | ||
value: [ "bing" ] | ||
- request: | ||
testName: trailers-only/duplicate-metadata | ||
streamType: STREAM_TYPE_UNARY | ||
requestMessages: | ||
- "@type": type.googleapis.com/connectrpc.conformance.v1.UnaryRequest | ||
responseDefinition: | ||
rawResponse: | ||
status_code: 200 | ||
headers: | ||
- name: content-type | ||
value: [ "application/grpc" ] | ||
- name: x-custom-trailer | ||
value: [ "bing", "quuz" ] | ||
- name: grpc-status | ||
value: [ "9" ] | ||
- name: grpc-message | ||
value: [ "error" ] | ||
# a "magic header" is required to get reference server to emit | ||
# valid HTTP/2 trailers-only frames (must have end-stream flag | ||
# on header frame; no data frame allowed) | ||
- name: x-connect-trailers-only | ||
value: ["1"] | ||
expectedResponse: | ||
error: | ||
code: 9 | ||
message: error | ||
responseTrailers: | ||
- name: x-custom-trailer | ||
value: [ "bing", "quuz" ] |