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

Function testDoneInfo

test/balancer_test.go:233–283  ·  view source on GitHub ↗
(t *testing.T, e env)

Source from the content-addressed store, hash-verified

231}
232
233func testDoneInfo(t *testing.T, e env) {
234 te := newTest(t, e)
235 b := &testBalancer{}
236 balancer.Register(b)
237 te.customDialOptions = []grpc.DialOption{
238 grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, testBalancerName)),
239 }
240 te.userAgent = failAppUA
241 te.startServer(&testServer{security: e.security})
242 defer te.tearDown()
243
244 cc := te.clientConn()
245 tc := testgrpc.NewTestServiceClient(cc)
246
247 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
248 defer cancel()
249 wantErr := detailedError
250 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); !testutils.StatusErrEqual(err, wantErr) {
251 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %v", status.Convert(err).Proto(), status.Convert(wantErr).Proto())
252 }
253 if _, err := tc.UnaryCall(ctx, &testpb.SimpleRequest{}); err != nil {
254 t.Fatalf("TestService.UnaryCall(%v, _, _, _) = _, %v; want _, <nil>", ctx, err)
255 }
256
257 if len(b.doneInfo) < 1 || !testutils.StatusErrEqual(b.doneInfo[0].Err, wantErr) {
258 t.Fatalf("b.doneInfo = %v; want b.doneInfo[0].Err = %v", b.doneInfo, wantErr)
259 }
260 if len(b.doneInfo) < 2 || !reflect.DeepEqual(b.doneInfo[1].Trailer, testTrailerMetadata) {
261 t.Fatalf("b.doneInfo = %v; want b.doneInfo[1].Trailer = %v", b.doneInfo, testTrailerMetadata)
262 }
263 if len(b.pickInfos) != len(b.doneInfo) {
264 t.Fatalf("Got %d picks, but %d doneInfo, want equal amount", len(b.pickInfos), len(b.doneInfo))
265 }
266 // To test done() is always called, even if it's returned with a non-Ready
267 // SubConn.
268 //
269 // Stop server and at the same time send RPCs. There are chances that picker
270 // is not updated in time, causing a non-Ready SubConn to be returned.
271 finished := make(chan struct{})
272 go func() {
273 for i := 0; i < 20; i++ {
274 tc.UnaryCall(ctx, &testpb.SimpleRequest{})
275 }
276 close(finished)
277 }()
278 te.srv.Stop()
279 <-finished
280 if len(b.pickInfos) != len(b.doneInfo) {
281 t.Fatalf("Got %d picks, %d doneInfo, want equal amount", len(b.pickInfos), len(b.doneInfo))
282 }
283}
284
285const loadMDKey = "X-Endpoint-Load-Metrics-Bin"
286

Callers 1

TestDoneInfoMethod · 0.85

Calls 13

EmptyCallMethod · 0.95
UnaryCallMethod · 0.95
RegisterFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
StatusErrEqualFunction · 0.92
ConvertFunction · 0.92
ProtoMethod · 0.80
newTestFunction · 0.70
FatalfMethod · 0.65
StopMethod · 0.65
startServerMethod · 0.45
tearDownMethod · 0.45

Tested by

no test coverage detected