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

Method TestClientConnRPC_WithNameResolutionDelay

test/clientconn_test.go:157–197  ·  view source on GitHub ↗

TestStatsHandlerDetectsResolutionDelay verifies that if this is the first time resolution is happening at the time of making RPC, nameResolutionDelayed flag is set indicating there was a delay in name resolution waiting for resolver to return addresses.

(t *testing.T)

Source from the content-addressed store, hash-verified

155// nameResolutionDelayed flag is set indicating there was a delay in name
156// resolution waiting for resolver to return addresses.
157func (s) TestClientConnRPC_WithNameResolutionDelay(t *testing.T) {
158 resolutionWait := grpcsync.NewEvent()
159 prevHook := internal.NewStreamWaitingForResolver
160 internal.NewStreamWaitingForResolver = func() { resolutionWait.Fire() }
161 defer func() { internal.NewStreamWaitingForResolver = prevHook }()
162
163 ss := &stubserver.StubServer{
164 EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) {
165 return &testpb.Empty{}, nil
166 },
167 }
168 if err := ss.Start(nil); err != nil {
169 t.Fatalf("Failed to start StubServer: %v", err)
170 }
171 defer ss.Stop()
172
173 statsHandler := &testStatsHandler{}
174 rb := manual.NewBuilderWithScheme("delayed")
175 cc, err := grpc.NewClient(rb.Scheme()+":///test.server",
176 grpc.WithTransportCredentials(insecure.NewCredentials()),
177 grpc.WithResolvers(rb),
178 grpc.WithStatsHandler(statsHandler),
179 )
180 if err != nil {
181 t.Fatalf("grpc.NewClient() failed: %v", err)
182 }
183 defer cc.Close()
184 go func() {
185 <-resolutionWait.Done()
186 rb.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: ss.Address}}})
187 }()
188 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
189 defer cancel()
190 client := testgrpc.NewTestServiceClient(cc)
191 if _, err := client.EmptyCall(ctx, &testpb.Empty{}); err != nil {
192 t.Fatalf("EmptyCall RPC failed: %v", err)
193 }
194 if !statsHandler.nameResolutionDelayed {
195 t.Fatalf("statsHandler.nameResolutionDelayed = %v; want true", statsHandler.nameResolutionDelayed)
196 }
197}

Callers

nothing calls this directly

Calls 15

FireMethod · 0.95
StartMethod · 0.95
StopMethod · 0.95
DoneMethod · 0.95
EmptyCallMethod · 0.95
NewEventFunction · 0.92
NewBuilderWithSchemeFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithResolversFunction · 0.92
WithStatsHandlerFunction · 0.92

Tested by

no test coverage detected