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

Method TestRPCWaitsForResolver

test/end2end_test.go:6287–6340  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6285}
6286
6287func (s) TestRPCWaitsForResolver(t *testing.T) {
6288 te := testServiceConfigSetup(t, tcpClearRREnv)
6289 te.startServer(&testServer{security: tcpClearRREnv.security})
6290 defer te.tearDown()
6291 r := manual.NewBuilderWithScheme("whatever")
6292
6293 te.resolverScheme = r.Scheme()
6294 cc := te.clientConn(grpc.WithResolvers(r))
6295 tc := testgrpc.NewTestServiceClient(cc)
6296
6297 ctx, cancel := context.WithTimeout(context.Background(), defaultTestShortTimeout)
6298 defer cancel()
6299 // With no resolved addresses yet, this will timeout.
6300 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); status.Code(err) != codes.DeadlineExceeded {
6301 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %s", err, codes.DeadlineExceeded)
6302 }
6303
6304 ctx, cancel = context.WithTimeout(context.Background(), defaultTestTimeout)
6305 defer cancel()
6306 go func() {
6307 time.Sleep(time.Second)
6308 r.UpdateState(resolver.State{
6309 Addresses: []resolver.Address{{Addr: te.srvAddr}},
6310 ServiceConfig: parseServiceConfig(t, r, `{
6311 "methodConfig": [
6312 {
6313 "name": [
6314 {
6315 "service": "grpc.testing.TestService",
6316 "method": "UnaryCall"
6317 }
6318 ],
6319 "maxRequestMessageBytes": 0
6320 }
6321 ]
6322 }`)})
6323 }()
6324 // We wait a second before providing a service config and resolving
6325 // addresses. So this will wait for that and then honor the
6326 // maxRequestMessageBytes it contains.
6327 payload, err := newPayload(testpb.PayloadType_COMPRESSABLE, 1)
6328 if err != nil {
6329 t.Fatal(err)
6330 }
6331 if _, err := tc.UnaryCall(ctx, &testpb.SimpleRequest{Payload: payload}); status.Code(err) != codes.ResourceExhausted {
6332 t.Fatalf("TestService/UnaryCall(_, _) = _, %v, want _, nil", err)
6333 }
6334 if got := ctx.Err(); got != nil {
6335 t.Fatalf("ctx.Err() = %v; want nil (deadline should be set short by service config)", got)
6336 }
6337 if _, err := tc.UnaryCall(ctx, &testpb.SimpleRequest{}); err != nil {
6338 t.Fatalf("TestService/UnaryCall(_, _) = _, %v, want _, nil", err)
6339 }
6340}
6341
6342type httpServerResponse struct {
6343 headers [][]string

Callers

nothing calls this directly

Calls 15

EmptyCallMethod · 0.95
UnaryCallMethod · 0.95
NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
testServiceConfigSetupFunction · 0.85
newPayloadFunction · 0.85
CodeMethod · 0.80
ErrMethod · 0.80
parseServiceConfigFunction · 0.70
SchemeMethod · 0.65
FatalfMethod · 0.65
UpdateStateMethod · 0.65

Tested by

no test coverage detected