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

Function testDoneLoads

test/balancer_test.go:305–344  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

303}
304
305func testDoneLoads(t *testing.T) {
306 b := &testBalancer{}
307 balancer.Register(b)
308
309 const testLoad = "test-load-,-should-be-orca"
310
311 ss := &stubserver.StubServer{
312 EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) {
313 grpc.SetTrailer(ctx, metadata.Pairs(loadMDKey, testLoad))
314 return &testpb.Empty{}, nil
315 },
316 }
317 if err := ss.Start(nil, grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, testBalancerName))); err != nil {
318 t.Fatalf("error starting testing server: %v", err)
319 }
320 defer ss.Stop()
321
322 tc := testgrpc.NewTestServiceClient(ss.CC)
323
324 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
325 defer cancel()
326 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != nil {
327 t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %v", err, nil)
328 }
329
330 piWant := []balancer.PickInfo{
331 {FullMethodName: "/grpc.testing.TestService/EmptyCall"},
332 }
333 if !reflect.DeepEqual(b.pickInfos, piWant) {
334 t.Fatalf("b.pickInfos = %v; want %v", b.pickInfos, piWant)
335 }
336
337 if len(b.doneInfo) < 1 {
338 t.Fatalf("b.doneInfo = %v, want length 1", b.doneInfo)
339 }
340 gotLoad, _ := b.doneInfo[0].ServerLoad.(string)
341 if gotLoad != testLoad {
342 t.Fatalf("b.doneInfo[0].ServerLoad = %v; want = %v", b.doneInfo[0].ServerLoad, testLoad)
343 }
344}
345
346type aiPicker struct {
347 result balancer.PickResult

Callers 1

TestDoneLoadsMethod · 0.85

Calls 8

StartMethod · 0.95
StopMethod · 0.95
EmptyCallMethod · 0.95
RegisterFunction · 0.92
SetTrailerFunction · 0.92
PairsFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
FatalfMethod · 0.65

Tested by

no test coverage detected