Skip to content

Commit 98d1550

Browse files
authored
xdsclient: switch more transport tests to e2e style (2/N) (#7693)
1 parent 9afb232 commit 98d1550

11 files changed

+511
-896
lines changed

xds/internal/xdsclient/authority.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type authorityArgs struct {
104104
serializer *grpcsync.CallbackSerializer
105105
resourceTypeGetter func(string) xdsresource.Type
106106
watchExpiryTimeout time.Duration
107+
backoff func(int) time.Duration // Backoff for ADS and LRS stream failures.
107108
logger *grpclog.PrefixLogger
108109
}
109110

@@ -123,6 +124,7 @@ func newAuthority(args authorityArgs) (*authority, error) {
123124
OnRecvHandler: ret.handleResourceUpdate,
124125
OnErrorHandler: ret.newConnectionError,
125126
OnSendHandler: ret.transportOnSendHandler,
127+
Backoff: args.backoff,
126128
Logger: args.logger,
127129
NodeProto: args.bootstrapCfg.Node(),
128130
})

xds/internal/xdsclient/client_new.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
"google.golang.org/grpc/internal"
28+
"google.golang.org/grpc/internal/backoff"
2829
"google.golang.org/grpc/internal/cache"
2930
"google.golang.org/grpc/internal/grpcsync"
3031
"google.golang.org/grpc/internal/xds/bootstrap"
@@ -53,16 +54,17 @@ const NameForServer = "#server"
5354
// only when all references are released, and it is safe for the caller to
5455
// invoke this close function multiple times.
5556
func New(name string) (XDSClient, func(), error) {
56-
return newRefCounted(name, defaultWatchExpiryTimeout, defaultIdleAuthorityDeleteTimeout)
57+
return newRefCounted(name, defaultWatchExpiryTimeout, defaultIdleAuthorityDeleteTimeout, backoff.DefaultExponential.Backoff)
5758
}
5859

5960
// newClientImpl returns a new xdsClient with the given config.
60-
func newClientImpl(config *bootstrap.Config, watchExpiryTimeout time.Duration, idleAuthorityDeleteTimeout time.Duration) (*clientImpl, error) {
61+
func newClientImpl(config *bootstrap.Config, watchExpiryTimeout time.Duration, idleAuthorityDeleteTimeout time.Duration, streamBackoff func(int) time.Duration) (*clientImpl, error) {
6162
ctx, cancel := context.WithCancel(context.Background())
6263
c := &clientImpl{
6364
done: grpcsync.NewEvent(),
6465
config: config,
6566
watchExpiryTimeout: watchExpiryTimeout,
67+
backoff: streamBackoff,
6668
serializer: grpcsync.NewCallbackSerializer(ctx),
6769
serializerClose: cancel,
6870
resourceTypes: newResourceTypeRegistry(),
@@ -90,6 +92,11 @@ type OptionsForTesting struct {
9092
// AuthorityIdleTimeout is the timeout before idle authorities are deleted.
9193
// If unspecified, uses the default value used in non-test code.
9294
AuthorityIdleTimeout time.Duration
95+
96+
// StreamBackoffAfterFailure is the backoff function used to determine the
97+
// backoff duration after stream failures. If unspecified, uses the default
98+
// value used in non-test code.
99+
StreamBackoffAfterFailure func(int) time.Duration
93100
}
94101

95102
// NewForTesting returns an xDS client configured with the provided options.
@@ -111,11 +118,14 @@ func NewForTesting(opts OptionsForTesting) (XDSClient, func(), error) {
111118
if opts.AuthorityIdleTimeout == 0 {
112119
opts.AuthorityIdleTimeout = defaultIdleAuthorityDeleteTimeout
113120
}
121+
if opts.StreamBackoffAfterFailure == nil {
122+
opts.StreamBackoffAfterFailure = defaultStreamBackoffFunc
123+
}
114124

115125
if err := bootstrap.SetFallbackBootstrapConfig(opts.Contents); err != nil {
116126
return nil, nil, err
117127
}
118-
client, cancel, err := newRefCounted(opts.Name, opts.WatchExpiryTimeout, opts.AuthorityIdleTimeout)
128+
client, cancel, err := newRefCounted(opts.Name, opts.WatchExpiryTimeout, opts.AuthorityIdleTimeout, opts.StreamBackoffAfterFailure)
119129
return client, func() { bootstrap.UnsetFallbackBootstrapConfigForTesting(); cancel() }, err
120130
}
121131

xds/internal/xdsclient/client_refcounted.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"sync/atomic"
2424
"time"
2525

26+
"google.golang.org/grpc/internal/backoff"
2627
"google.golang.org/grpc/internal/grpcsync"
2728
"google.golang.org/grpc/internal/xds/bootstrap"
2829
)
@@ -37,6 +38,8 @@ var (
3738
// overridden in tests to give them visibility into certain events.
3839
xdsClientImplCreateHook = func(string) {}
3940
xdsClientImplCloseHook = func(string) {}
41+
42+
defaultStreamBackoffFunc = backoff.DefaultExponential.Backoff
4043
)
4144

4245
func clientRefCountedClose(name string) {
@@ -60,7 +63,7 @@ func clientRefCountedClose(name string) {
6063
// newRefCounted creates a new reference counted xDS client implementation for
6164
// name, if one does not exist already. If an xDS client for the given name
6265
// exists, it gets a reference to it and returns it.
63-
func newRefCounted(name string, watchExpiryTimeout, idleAuthorityTimeout time.Duration) (XDSClient, func(), error) {
66+
func newRefCounted(name string, watchExpiryTimeout, idleAuthorityTimeout time.Duration, streamBackoff func(int) time.Duration) (XDSClient, func(), error) {
6467
clientsMu.Lock()
6568
defer clientsMu.Unlock()
6669

@@ -74,7 +77,7 @@ func newRefCounted(name string, watchExpiryTimeout, idleAuthorityTimeout time.Du
7477
if err != nil {
7578
return nil, nil, fmt.Errorf("xds: failed to get xDS bootstrap config: %v", err)
7679
}
77-
c, err := newClientImpl(config, watchExpiryTimeout, idleAuthorityTimeout)
80+
c, err := newClientImpl(config, watchExpiryTimeout, idleAuthorityTimeout, streamBackoff)
7881
if err != nil {
7982
return nil, nil, err
8083
}

xds/internal/xdsclient/clientimpl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type clientImpl struct {
3737
config *bootstrap.Config
3838
logger *grpclog.PrefixLogger
3939
watchExpiryTimeout time.Duration
40+
backoff func(int) time.Duration // Backoff for ADS and LRS stream failures.
4041
serializer *grpcsync.CallbackSerializer
4142
serializerClose func()
4243
resourceTypes *resourceTypeRegistry

xds/internal/xdsclient/clientimpl_authority.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func (c *clientImpl) newAuthorityLocked(config *bootstrap.ServerConfig) (_ *auth
114114
serializer: c.serializer,
115115
resourceTypeGetter: c.resourceTypes.get,
116116
watchExpiryTimeout: c.watchExpiryTimeout,
117+
backoff: c.backoff,
117118
logger: grpclog.NewPrefixLogger(logger, authorityPrefix(c, config.ServerURI())),
118119
})
119120
if err != nil {

0 commit comments

Comments
 (0)