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

Method TestPickFirst_InitialResolverError

balancer/pickfirst/pickfirst_test.go:55–83  ·  view source on GitHub ↗

TestPickFirst_InitialResolverError sends a resolver error to the balancer before a valid resolver update. It verifies that the clientconn state is updated to TRANSIENT_FAILURE.

(t *testing.T)

Source from the content-addressed store, hash-verified

53// before a valid resolver update. It verifies that the clientconn state is
54// updated to TRANSIENT_FAILURE.
55func (s) TestPickFirst_InitialResolverError(t *testing.T) {
56 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
57 defer cancel()
58 cc := testutils.NewBalancerClientConn(t)
59 bal := balancer.Get(Name).Build(cc, balancer.BuildOptions{})
60 defer bal.Close()
61 bal.ResolverError(errors.New("resolution failed: test error"))
62
63 if err := cc.WaitForConnectivityState(ctx, connectivity.TransientFailure); err != nil {
64 t.Fatalf("cc.WaitForConnectivityState(%v) returned error: %v", connectivity.TransientFailure, err)
65 }
66
67 // After sending a valid update, the LB policy should report CONNECTING.
68 ccState := balancer.ClientConnState{
69 ResolverState: resolver.State{
70 Endpoints: []resolver.Endpoint{
71 {Addresses: []resolver.Address{{Addr: "1.1.1.1:1"}}},
72 {Addresses: []resolver.Address{{Addr: "2.2.2.2:2"}}},
73 },
74 },
75 }
76 if err := bal.UpdateClientConnState(ccState); err != nil {
77 t.Fatalf("UpdateClientConnState(%v) returned error: %v", ccState, err)
78 }
79
80 if err := cc.WaitForConnectivityState(ctx, connectivity.Connecting); err != nil {
81 t.Fatalf("cc.WaitForConnectivityState(%v) returned error: %v", connectivity.Connecting, err)
82 }
83}
84
85// TestPickFirst_ResolverErrorinTF sends a resolver error to the balancer
86// before when it's attempting to connect to a SubConn TRANSIENT_FAILURE. It

Callers

nothing calls this directly

Calls 8

NewBalancerClientConnFunction · 0.92
GetFunction · 0.92
BuildMethod · 0.65
CloseMethod · 0.65
ResolverErrorMethod · 0.65
FatalfMethod · 0.65
UpdateClientConnStateMethod · 0.65

Tested by

no test coverage detected