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

Method TestGoodUpdateThenResolverError

balancer/lazy/lazy_ext_test.go:193–295  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

191// resolver error. The test verifies that the child balancer receives the good
192// update followed by the error.
193func (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

Callers

nothing calls this directly

Calls 15

HasFiredMethod · 0.95
FireMethod · 0.95
EmptyCallMethod · 0.95
DoneMethod · 0.95
StartTestServiceFunction · 0.92
NewEventFunction · 0.92
GetFunction · 0.92
RegisterFunction · 0.92
NewBalancerFunction · 0.92
NewBuilderWithSchemeFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92

Tested by

no test coverage detected