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

Method TestClientConnRPC_WithoutNameResolutionDelay

test/clientconn_test.go:120–151  ·  view source on GitHub ↗

TestClientConnRPC_WithoutNameResolutionDelay verify that if the resolution has already happened once before at the time of making RPC, the name resolution flag is not set indicating there was no delay in name resolution.

(t *testing.T)

Source from the content-addressed store, hash-verified

118// has already happened once before at the time of making RPC, the name
119// resolution flag is not set indicating there was no delay in name resolution.
120func (s) TestClientConnRPC_WithoutNameResolutionDelay(t *testing.T) {
121 statsHandler := &testStatsHandler{}
122 ss := &stubserver.StubServer{
123 EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) {
124 return &testpb.Empty{}, nil
125 },
126 }
127 if err := ss.Start(nil, grpc.WithStatsHandler(statsHandler)); err != nil {
128 t.Fatalf("Failed to start StubServer: %v", err)
129 }
130 defer ss.Stop()
131
132 rb := manual.NewBuilderWithScheme("instant")
133 rb.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: ss.Address}}})
134 cc := ss.CC
135 defer cc.Close()
136
137 cc.Connect()
138 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
139 defer cancel()
140 testutils.AwaitState(ctx, t, cc, connectivity.Ready)
141 client := testgrpc.NewTestServiceClient(cc)
142 // Verify that the RPC succeeds.
143 if _, err := client.EmptyCall(ctx, &testpb.Empty{}); err != nil {
144 t.Fatalf("First RPC failed unexpectedly: %v", err)
145 }
146 // verifying that RPC was not blocked on resolver indicating there was no
147 // delay in name resolution.
148 if statsHandler.nameResolutionDelayed {
149 t.Fatalf("statsHandler.nameResolutionDelayed = %v; want false", statsHandler.nameResolutionDelayed)
150 }
151}
152
153// TestStatsHandlerDetectsResolutionDelay verifies that if this is the
154// first time resolution is happening at the time of making RPC,

Callers

nothing calls this directly

Calls 10

StartMethod · 0.95
StopMethod · 0.95
EmptyCallMethod · 0.95
WithStatsHandlerFunction · 0.92
NewBuilderWithSchemeFunction · 0.92
AwaitStateFunction · 0.92
InitialStateMethod · 0.80
FatalfMethod · 0.65
CloseMethod · 0.65
ConnectMethod · 0.65

Tested by

no test coverage detected