Tests the scenario when a resolver produces a good state followed by a resolver error. The test verifies that the child balancer receives the good update followed by the error.
(t *testing.T)
| 191 | // resolver error. The test verifies that the child balancer receives the good |
| 192 | // update followed by the error. |
| 193 | func (s) TestGoodUpdateThenResolverError(t *testing.T) { |
| 194 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 195 | defer cancel() |
| 196 | |
| 197 | backend := stubserver.StartTestService(t, nil) |
| 198 | defer backend.Stop() |
| 199 | resolverStateReceived := false |
| 200 | resolverErrorReceived := grpcsync.NewEvent() |
| 201 | |
| 202 | childBF := stub.BalancerFuncs{ |
| 203 | Init: func(bd *stub.BalancerData) { |
| 204 | bd.ChildBalancer = balancer.Get(pickfirst.Name).Build(bd.ClientConn, bd.BuildOptions) |
| 205 | }, |
| 206 | UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error { |
| 207 | if resolverErrorReceived.HasFired() { |
| 208 | t.Error("Received resolver error before resolver state.") |
| 209 | } |
| 210 | resolverStateReceived = true |
| 211 | return bd.ChildBalancer.UpdateClientConnState(ccs) |
| 212 | }, |
| 213 | ResolverError: func(bd *stub.BalancerData, err error) { |
| 214 | if !resolverStateReceived { |
| 215 | t.Error("Received resolver error before resolver state.") |
| 216 | } |
| 217 | resolverErrorReceived.Fire() |
| 218 | bd.ChildBalancer.ResolverError(err) |
| 219 | }, |
| 220 | Close: func(bd *stub.BalancerData) { |
| 221 | bd.ChildBalancer.Close() |
| 222 | }, |
| 223 | } |
| 224 | |
| 225 | childBalName := strings.ReplaceAll(strings.ToLower(t.Name())+"_child", "/", "") |
| 226 | stub.Register(childBalName, childBF) |
| 227 | |
| 228 | topLevelBF := stub.BalancerFuncs{ |
| 229 | Init: func(bd *stub.BalancerData) { |
| 230 | bd.ChildBalancer = lazy.NewBalancer(bd.ClientConn, bd.BuildOptions, balancer.Get(childBalName).Build) |
| 231 | }, |
| 232 | ExitIdle: func(*stub.BalancerData) { |
| 233 | t.Log("Ignoring call to ExitIdle to delay lazy child creation until RPC time.") |
| 234 | }, |
| 235 | ResolverError: func(bd *stub.BalancerData, err error) { |
| 236 | bd.ChildBalancer.ResolverError(err) |
| 237 | }, |
| 238 | UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error { |
| 239 | return bd.ChildBalancer.UpdateClientConnState(ccs) |
| 240 | }, |
| 241 | Close: func(bd *stub.BalancerData) { |
| 242 | bd.ChildBalancer.Close() |
| 243 | }, |
| 244 | } |
| 245 | |
| 246 | topLevelBalName := strings.ReplaceAll(strings.ToLower(t.Name())+"_top_level", "/", "") |
| 247 | stub.Register(topLevelBalName, topLevelBF) |
| 248 | |
| 249 | json := fmt.Sprintf(`{"loadBalancingConfig": [{%q: {}}]}`, topLevelBalName) |
| 250 |
nothing calls this directly
no test coverage detected