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

Method TestBalancerGroupBuildOptions

internal/balancergroup/balancergroup_test.go:449–487  ·  view source on GitHub ↗

TestBalancerGroupBuildOptions verifies that the balancer.BuildOptions passed to the balancergroup at creation time is passed to child policies.

(t *testing.T)

Source from the content-addressed store, hash-verified

447// TestBalancerGroupBuildOptions verifies that the balancer.BuildOptions passed
448// to the balancergroup at creation time is passed to child policies.
449func (s) TestBalancerGroupBuildOptions(t *testing.T) {
450 const (
451 balancerName = "stubBalancer-TestBalancerGroupBuildOptions"
452 userAgent = "ua"
453 )
454
455 // Setup the stub balancer such that we can read the build options passed to
456 // it in the UpdateClientConnState method.
457 bOpts := balancer.BuildOptions{
458 DialCreds: insecure.NewCredentials(),
459 ChannelzParent: channelz.RegisterChannel(nil, "test channel"),
460 CustomUserAgent: userAgent,
461 }
462 stub.Register(balancerName, stub.BalancerFuncs{
463 UpdateClientConnState: func(bd *stub.BalancerData, _ balancer.ClientConnState) error {
464 if bd.BuildOptions.DialCreds != bOpts.DialCreds || bd.BuildOptions.ChannelzParent != bOpts.ChannelzParent || bd.BuildOptions.CustomUserAgent != bOpts.CustomUserAgent {
465 return fmt.Errorf("buildOptions in child balancer: %v, want %v", bd, bOpts)
466 }
467 return nil
468 },
469 })
470 cc := testutils.NewBalancerClientConn(t)
471 bg := balancergroup.New(balancergroup.Options{
472 CC: cc,
473 BuildOpts: bOpts,
474 StateAggregator: nil,
475 Logger: nil,
476 })
477
478 // Add the stub balancer build above as a child policy.
479 balancerBuilder := balancer.Get(balancerName)
480 bg.Add(testBalancerIDs[0], balancerBuilder)
481
482 // Send an empty clientConn state change. This should trigger the
483 // verification of the buildOptions being passed to the child policy.
484 if err := bg.UpdateClientConnState(testBalancerIDs[0], balancer.ClientConnState{}); err != nil {
485 t.Fatal(err)
486 }
487}
488
489func (s) TestBalancerGroup_UpdateClientConnState_AfterClose(t *testing.T) {
490 balancerName := t.Name()

Callers

nothing calls this directly

Calls 10

NewCredentialsFunction · 0.92
RegisterChannelFunction · 0.92
RegisterFunction · 0.92
NewBalancerClientConnFunction · 0.92
NewFunction · 0.92
GetFunction · 0.92
ErrorfMethod · 0.65
AddMethod · 0.65
UpdateClientConnStateMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected