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

Method TestCanceledStatus

binarylog/binarylog_end2end_test.go:1021–1053  ·  view source on GitHub ↗

TestCanceledStatus ensures a server that responds with a Canceled status has its trailers logged appropriately and is not treated as a canceled RPC.

(t *testing.T)

Source from the content-addressed store, hash-verified

1019// TestCanceledStatus ensures a server that responds with a Canceled status has
1020// its trailers logged appropriately and is not treated as a canceled RPC.
1021func (s) TestCanceledStatus(t *testing.T) {
1022 defer testSink.clear()
1023
1024 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
1025 defer cancel()
1026
1027 const statusMsgWant = "server returned Canceled"
1028 ss := &stubserver.StubServer{
1029 UnaryCallF: func(ctx context.Context, _ *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
1030 grpc.SetTrailer(ctx, metadata.Pairs("key", "value"))
1031 return nil, status.Error(codes.Canceled, statusMsgWant)
1032 },
1033 }
1034 if err := ss.Start(nil); err != nil {
1035 t.Fatalf("Error starting endpoint server: %v", err)
1036 }
1037 defer ss.Stop()
1038
1039 if _, err := ss.Client.UnaryCall(ctx, &testpb.SimpleRequest{}); status.Code(err) != codes.Canceled {
1040 t.Fatalf("Received unexpected error from UnaryCall: %v; want Canceled", err)
1041 }
1042
1043 got := testSink.logEntries(true)
1044 last := got[len(got)-1]
1045 if last.Type != binlogpb.GrpcLogEntry_EVENT_TYPE_SERVER_TRAILER ||
1046 last.GetTrailer().GetStatusCode() != uint32(codes.Canceled) ||
1047 last.GetTrailer().GetStatusMessage() != statusMsgWant ||
1048 len(last.GetTrailer().GetMetadata().GetEntry()) != 1 ||
1049 last.GetTrailer().GetMetadata().GetEntry()[0].GetKey() != "key" ||
1050 string(last.GetTrailer().GetMetadata().GetEntry()[0].GetValue()) != "value" {
1051 t.Fatalf("Got binary log: %+v; want last entry is server trailing with status Canceled", got)
1052 }
1053}

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
StopMethod · 0.95
SetTrailerFunction · 0.92
PairsFunction · 0.92
ErrorFunction · 0.92
CodeFunction · 0.92
logEntriesMethod · 0.80
GetTrailerMethod · 0.80
GetStatusMessageMethod · 0.80
GetEntryMethod · 0.80
FatalfMethod · 0.65
UnaryCallMethod · 0.65

Tested by

no test coverage detected