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

Method TestEnterIdleDuringBalancerUpdateState

resolver_balancer_ext_test.go:218–257  ·  view source on GitHub ↗

TestEnterIdleDuringBalancerUpdateState tests calling UpdateState at the same time as the balancer being closed while the channel enters idle mode.

(t *testing.T)

Source from the content-addressed store, hash-verified

216// TestEnterIdleDuringBalancerUpdateState tests calling UpdateState at the same
217// time as the balancer being closed while the channel enters idle mode.
218func (s) TestEnterIdleDuringBalancerUpdateState(t *testing.T) {
219 enterIdle := internal.EnterIdleModeForTesting.(func(*grpc.ClientConn))
220 name := strings.ReplaceAll(strings.ToLower(t.Name()), "/", "")
221
222 // Create a balancer that calls UpdateState once asynchronously, attempting
223 // to make the channel appear ready even after entering idle.
224 bf := stub.BalancerFuncs{
225 UpdateClientConnState: func(bd *stub.BalancerData, _ balancer.ClientConnState) error {
226 go func() {
227 bd.ClientConn.UpdateState(balancer.State{ConnectivityState: connectivity.Ready})
228 }()
229 return nil
230 },
231 }
232 stub.Register(name, bf)
233
234 rb := manual.NewBuilderWithScheme(name)
235 rb.BuildCallback = func(_ resolver.Target, cc resolver.ClientConn, _ resolver.BuildOptions) {
236 cc.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: "test"}}})
237 }
238 resolver.Register(rb)
239
240 cc, err := grpc.NewClient(
241 name+":///",
242 grpc.WithTransportCredentials(insecure.NewCredentials()),
243 grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"`+name+`":{}}]}`))
244 if err != nil {
245 t.Fatalf("grpc.NewClient error: %v", err)
246 }
247 defer cc.Close()
248
249 // Enter/exit idle mode repeatedly.
250 for i := 0; i < 2000; i++ {
251 enterIdle(cc)
252 if got, want := cc.GetState(), connectivity.Idle; got != want {
253 t.Fatalf("cc state = %v; want %v", got, want)
254 }
255 cc.Connect()
256 }
257}
258
259// TestEnterIdleDuringBalancerNewSubConn tests calling NewSubConn at the same
260// time as the balancer being closed while the channel enters idle mode.

Callers

nothing calls this directly

Calls 13

RegisterFunction · 0.92
NewBuilderWithSchemeFunction · 0.92
RegisterFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
NameMethod · 0.65
UpdateStateMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
GetStateMethod · 0.65

Tested by

no test coverage detected