NewClientForTesting returns an xDS client configured with the provided options from the pool. If the client doesn't already exist, it creates a new xDS client and adds it to the pool. The second return value represents a close function which the caller is expected to invoke once they are done using
(opts OptionsForTesting)
| 130 | // |
| 131 | // This function should ONLY be used for testing purposes. |
| 132 | func (p *Pool) NewClientForTesting(opts OptionsForTesting) (XDSClient, func(), error) { |
| 133 | if opts.Name == "" { |
| 134 | return nil, nil, fmt.Errorf("xds: opts.Name field must be non-empty") |
| 135 | } |
| 136 | if opts.WatchExpiryTimeout == 0 { |
| 137 | opts.WatchExpiryTimeout = defaultWatchExpiryTimeout |
| 138 | } |
| 139 | if opts.StreamBackoffAfterFailure == nil { |
| 140 | opts.StreamBackoffAfterFailure = defaultExponentialBackoff |
| 141 | } |
| 142 | if opts.MetricsRecorder == nil { |
| 143 | opts.MetricsRecorder = istats.NewMetricsRecorderList(nil) |
| 144 | } |
| 145 | c, cancel, err := p.newRefCounted(opts.Name, opts.MetricsRecorder, opts.WatchExpiryTimeout, opts.Config) |
| 146 | if err != nil { |
| 147 | return nil, nil, err |
| 148 | } |
| 149 | return c, cancel, nil |
| 150 | } |
| 151 | |
| 152 | // GetClientForTesting returns an xDS client created earlier using the given |
| 153 | // name from the pool. If the client with the given name doesn't already exist, |