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)
| 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. |
| 1021 | func (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 | } |
nothing calls this directly
no test coverage detected