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

Method TestConcurrentRPCs

balancer/leastrequest/leastrequest_test.go:475–522  ·  view source on GitHub ↗

TestConcurrentRPCs tests concurrent RPCs on the least request balancer. It configures a channel with a least request balancer as the top level balancer, and makes 100 RPCs asynchronously. This makes sure no race conditions happen in this scenario.

(t *testing.T)

Source from the content-addressed store, hash-verified

473// and makes 100 RPCs asynchronously. This makes sure no race conditions happen
474// in this scenario.
475func (s) TestConcurrentRPCs(t *testing.T) {
476 addresses := setupBackends(t, 3)
477
478 mr := manual.NewBuilderWithScheme("lr-e2e")
479 defer mr.Close()
480
481 // Configure least request as top level balancer of channel.
482 lrscJSON := `
483{
484 "loadBalancingConfig": [
485 {
486 "least_request_experimental": {
487 "choiceCount": 2
488 }
489 }
490 ]
491}`
492 sc := internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult)(lrscJSON)
493 firstTwoAddresses := []resolver.Address{
494 {Addr: addresses[0]},
495 {Addr: addresses[1]},
496 }
497 mr.InitialState(resolver.State{
498 Addresses: firstTwoAddresses,
499 ServiceConfig: sc,
500 })
501
502 cc, err := grpc.NewClient(mr.Scheme()+":///", grpc.WithResolvers(mr), grpc.WithTransportCredentials(insecure.NewCredentials()))
503 if err != nil {
504 t.Fatalf("grpc.NewClient() failed: %v", err)
505 }
506 defer cc.Close()
507 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
508 defer cancel()
509 testServiceClient := testgrpc.NewTestServiceClient(cc)
510
511 var wg sync.WaitGroup
512 for i := 0; i < 100; i++ {
513 wg.Add(1)
514 go func() {
515 defer wg.Done()
516 for j := 0; j < 5; j++ {
517 testServiceClient.EmptyCall(ctx, &testpb.Empty{})
518 }
519 }()
520 }
521 wg.Wait()
522}
523
524// Test tests that the least request balancer persists RPC counts once it gets
525// new picker updates and backends within an endpoint go down. It first updates

Callers

nothing calls this directly

Calls 14

EmptyCallMethod · 0.95
NewBuilderWithSchemeFunction · 0.92
NewClientFunction · 0.92
WithResolversFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
InitialStateMethod · 0.80
WaitMethod · 0.80
setupBackendsFunction · 0.70
CloseMethod · 0.65
SchemeMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected