TestEnterIdleDuringBalancerUpdateState tests calling UpdateState at the same time as the balancer being closed while the channel enters idle mode.
(t *testing.T)
| 216 | // TestEnterIdleDuringBalancerUpdateState tests calling UpdateState at the same |
| 217 | // time as the balancer being closed while the channel enters idle mode. |
| 218 | func (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. |
nothing calls this directly
no test coverage detected