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

Method TestBalancerExitIdle_All

internal/balancergroup/balancergroup_test.go:762–821  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

760}
761
762func (s) TestBalancerExitIdle_All(t *testing.T) {
763 balancer1 := t.Name() + "-1"
764 balancer2 := t.Name() + "-2"
765
766 testID1, testID2 := testBalancerIDs[0], testBalancerIDs[1]
767
768 exitIdleCh1, exitIdleCh2 := make(chan struct{}, 1), make(chan struct{}, 1)
769
770 stub.Register(balancer1, stub.BalancerFuncs{
771 ExitIdle: func(_ *stub.BalancerData) {
772 exitIdleCh1 <- struct{}{}
773 },
774 })
775
776 stub.Register(balancer2, stub.BalancerFuncs{
777 ExitIdle: func(_ *stub.BalancerData) {
778 exitIdleCh2 <- struct{}{}
779 },
780 })
781
782 cc := testutils.NewBalancerClientConn(t)
783 bg := balancergroup.New(balancergroup.Options{
784 CC: cc,
785 BuildOpts: balancer.BuildOptions{},
786 StateAggregator: nil,
787 Logger: nil,
788 })
789 defer bg.Close()
790
791 bg.Add(testID1, balancer.Get(balancer1))
792 bg.Add(testID2, balancer.Get(balancer2))
793
794 bg.ExitIdle()
795
796 errCh := make(chan error, 2)
797
798 go func() {
799 select {
800 case <-exitIdleCh1:
801 errCh <- nil
802 case <-time.After(defaultTestTimeout):
803 errCh <- fmt.Errorf("timeout waiting for ExitIdle on balancer1")
804 }
805 }()
806
807 go func() {
808 select {
809 case <-exitIdleCh2:
810 errCh <- nil
811 case <-time.After(defaultTestTimeout):
812 errCh <- fmt.Errorf("timeout waiting for ExitIdle on balancer2")
813 }
814 }()
815
816 for i := 0; i < 2; i++ {
817 if err := <-errCh; err != nil {
818 t.Fatal(err)
819 }

Callers

nothing calls this directly

Calls 10

RegisterFunction · 0.92
NewBalancerClientConnFunction · 0.92
NewFunction · 0.92
GetFunction · 0.92
NameMethod · 0.65
CloseMethod · 0.65
AddMethod · 0.65
ExitIdleMethod · 0.65
ErrorfMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected