Skip to content

Commit bc9a413

Browse files
committed
Fix TestAuthenticateToAnything and reduce calls to atomic.Pointer.Load
1 parent f0bc695 commit bc9a413

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

x/mongo/driver/topology/topology_options.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,12 @@ func NewAuthenticatorConfig(authenticator driver.Authenticator, clientOpts ...Au
292292
ClusterClock: clock,
293293
}
294294

295-
if driverInfo := settings.driverInfo; driverInfo != nil && driverInfo.Load() != nil {
296-
handshakeOpts.OuterLibraryName = driverInfo.Load().Name
297-
handshakeOpts.OuterLibraryVersion = driverInfo.Load().Version
298-
handshakeOpts.OuterLibraryPlatform = driverInfo.Load().Platform
295+
if settings.driverInfo != nil {
296+
if di := settings.driverInfo.Load(); di != nil {
297+
handshakeOpts.OuterLibraryName = di.Name
298+
handshakeOpts.OuterLibraryVersion = di.Version
299+
handshakeOpts.OuterLibraryPlatform = di.Platform
300+
}
299301
}
300302

301303
if opts.Auth.AuthMechanism == "" {
@@ -317,22 +319,22 @@ func NewAuthenticatorConfig(authenticator driver.Authenticator, clientOpts ...Au
317319

318320
} else {
319321
handshaker = func(driver.Handshaker) driver.Handshaker {
320-
var outerLibraryName, outerLibraryVersion, outerLibraryPlatform string
321-
if driverInfo := settings.driverInfo; driverInfo != nil && driverInfo.Load() != nil {
322-
outerLibraryName = driverInfo.Load().Name
323-
outerLibraryVersion = driverInfo.Load().Version
324-
outerLibraryPlatform = driverInfo.Load().Platform
325-
}
326-
327-
return operation.NewHello().
322+
op := operation.NewHello().
328323
AppName(appName).
329324
Compressors(comps).
330325
ClusterClock(clock).
331326
ServerAPI(serverAPI).
332-
LoadBalanced(loadBalanced).
333-
OuterLibraryName(outerLibraryName).
334-
OuterLibraryVersion(outerLibraryVersion).
335-
OuterLibraryPlatform(outerLibraryPlatform)
327+
LoadBalanced(loadBalanced)
328+
329+
if settings.driverInfo != nil {
330+
if di := settings.driverInfo.Load(); di != nil {
331+
op = op.OuterLibraryName(di.Name).
332+
OuterLibraryVersion(di.Version).
333+
OuterLibraryPlatform(di.Platform)
334+
}
335+
}
336+
337+
return op
336338
}
337339
}
338340

x/mongo/driver/topology/topology_options_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func TestAuthenticateToAnything(t *testing.T) {
149149
opt := options.Client().SetAuth(options.Credential{Username: "foo", Password: "bar"})
150150
err := tc.set(opt)
151151
require.NoError(t, err, "error setting authenticateToAnything: %v", err)
152-
cfg, err := NewAuthenticatorConfig(nil, WithAuthConfigClientOptions(opt))
152+
cfg, err := NewAuthenticatorConfig(&testAuthenticator{}, WithAuthConfigClientOptions(opt))
153153
require.NoError(t, err, "error constructing topology config: %v", err)
154154

155155
srvrCfg := newServerConfig(defaultConnectionTimeout, cfg.ServerOpts...)

0 commit comments

Comments
 (0)