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

Method TestResolverBuildFailure

resolver_balancer_ext_test.go:112–134  ·  view source on GitHub ↗

TestResolverBuildFailure tests: 1. resolver.Builder.Build() passes. 2. Channel enters idle mode. 3. An RPC happens. 4. resolver.Builder.Build() fails.

(t *testing.T)

Source from the content-addressed store, hash-verified

110// 3. An RPC happens.
111// 4. resolver.Builder.Build() fails.
112func (s) TestResolverBuildFailure(t *testing.T) {
113 enterIdle := internal.EnterIdleModeForTesting.(func(*grpc.ClientConn))
114 name := strings.ReplaceAll(strings.ToLower(t.Name()), "/", "")
115 resErrCh := make(chan error, 1)
116 resolver.Register(&resolverBuilderWithErr{errCh: resErrCh, scheme: name})
117
118 resErrCh <- nil
119 cc, err := grpc.NewClient(name+":///", grpc.WithTransportCredentials(insecure.NewCredentials()))
120 if err != nil {
121 t.Fatalf("grpc.NewClient error: %v", err)
122 }
123 defer cc.Close()
124 cc.Connect()
125 enterIdle(cc)
126 const errStr = "test error from resolver builder"
127 t.Log("pushing res err")
128 resErrCh <- errors.New(errStr)
129 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
130 defer cancel()
131 if err := cc.Invoke(ctx, "/a/b", nil, nil); err == nil || !strings.Contains(err.Error(), errStr) {
132 t.Fatalf("Invoke = %v; want %v", err, errStr)
133 }
134}
135
136// Tests the case where the resolver reports an error to the channel before
137// reporting an update. Verifies that the channel eventually moves to

Callers

nothing calls this directly

Calls 11

RegisterFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
NameMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
ConnectMethod · 0.65
LogMethod · 0.65
InvokeMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected