mirror of https://github.com/grpc/grpc-go.git
client: Revert dialWithGlobalOption (#6012)
This commit is contained in:
parent
d655f404da
commit
ceb3f07190
|
|
@ -133,10 +133,6 @@ func (dcs *defaultConfigSelector) SelectConfig(rpcInfo iresolver.RPCInfo) (*ires
|
||||||
// https://github.com/grpc/grpc/blob/master/doc/naming.md.
|
// https://github.com/grpc/grpc/blob/master/doc/naming.md.
|
||||||
// e.g. to use dns resolver, a "dns:///" prefix should be applied to the target.
|
// e.g. to use dns resolver, a "dns:///" prefix should be applied to the target.
|
||||||
func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *ClientConn, err error) {
|
func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *ClientConn, err error) {
|
||||||
return dialWithGlobalOptions(ctx, target, false, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func dialWithGlobalOptions(ctx context.Context, target string, disableGlobalOptions bool, opts ...DialOption) (conn *ClientConn, err error) {
|
|
||||||
cc := &ClientConn{
|
cc := &ClientConn{
|
||||||
target: target,
|
target: target,
|
||||||
csMgr: &connectivityStateManager{},
|
csMgr: &connectivityStateManager{},
|
||||||
|
|
@ -150,11 +146,9 @@ func dialWithGlobalOptions(ctx context.Context, target string, disableGlobalOpti
|
||||||
cc.safeConfigSelector.UpdateConfigSelector(&defaultConfigSelector{nil})
|
cc.safeConfigSelector.UpdateConfigSelector(&defaultConfigSelector{nil})
|
||||||
cc.ctx, cc.cancel = context.WithCancel(context.Background())
|
cc.ctx, cc.cancel = context.WithCancel(context.Background())
|
||||||
|
|
||||||
if !disableGlobalOptions {
|
|
||||||
for _, opt := range globalDialOptions {
|
for _, opt := range globalDialOptions {
|
||||||
opt.apply(&cc.dopts)
|
opt.apply(&cc.dopts)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt.apply(&cc.dopts)
|
opt.apply(&cc.dopts)
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -59,24 +58,6 @@ func (s) TestAddGlobalDialOptions(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestDisableGlobalOptions tests dialing with a bit that disables global
|
|
||||||
// options. Dialing with this bit set should not pick up global options.
|
|
||||||
func (s) TestDisableGlobalOptions(t *testing.T) {
|
|
||||||
// Set transport credentials as a global option.
|
|
||||||
internal.AddGlobalDialOptions.(func(opt ...DialOption))(WithTransportCredentials(insecure.NewCredentials()))
|
|
||||||
// Dial with disable global options set to true. This Dial should fail due
|
|
||||||
// to the global dial options with credentials not being picked up due to it
|
|
||||||
// being disabled.
|
|
||||||
if _, err := internal.DialWithGlobalOptions.(func(context.Context, string, bool, ...DialOption) (*ClientConn, error))(context.Background(), "fake", true); err == nil {
|
|
||||||
t.Fatalf("Dialing without a credential did not fail")
|
|
||||||
} else {
|
|
||||||
if !strings.Contains(err.Error(), "no transport security set") {
|
|
||||||
t.Fatalf("Dialing failed with unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal.ClearGlobalDialOptions()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s) TestAddGlobalServerOptions(t *testing.T) {
|
func (s) TestAddGlobalServerOptions(t *testing.T) {
|
||||||
const maxRecvSize = 998765
|
const maxRecvSize = 998765
|
||||||
// Set and check the ServerOptions
|
// Set and check the ServerOptions
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ func init() {
|
||||||
internal.ClearGlobalDialOptions = func() {
|
internal.ClearGlobalDialOptions = func() {
|
||||||
globalDialOptions = nil
|
globalDialOptions = nil
|
||||||
}
|
}
|
||||||
internal.DialWithGlobalOptions = dialWithGlobalOptions
|
|
||||||
internal.WithBinaryLogger = withBinaryLogger
|
internal.WithBinaryLogger = withBinaryLogger
|
||||||
internal.JoinDialOptions = newJoinDialOption
|
internal.JoinDialOptions = newJoinDialOption
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// DialWithGlobalOptions dials with a knob on whether to disable global dial
|
|
||||||
// options (set via AddGlobalDialOptions).
|
|
||||||
DialWithGlobalOptions interface{} // func (context.Context, string, bool, ...DialOption) (*ClientConn, error)
|
|
||||||
// WithHealthCheckFunc is set by dialoptions.go
|
// WithHealthCheckFunc is set by dialoptions.go
|
||||||
WithHealthCheckFunc interface{} // func (HealthChecker) DialOption
|
WithHealthCheckFunc interface{} // func (HealthChecker) DialOption
|
||||||
// HealthCheckFunc is used to provide client-side LB channel health checking
|
// HealthCheckFunc is used to provide client-side LB channel health checking
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue