@@ -128,10 +128,10 @@ type T struct {
128
128
succeeded []* event.CommandSucceededEvent
129
129
failed []* event.CommandFailedEvent
130
130
131
- Client * mongo.Client
132
- fpClient * mongo.Client
133
- DB * mongo.Database
134
- Coll * mongo.Collection
131
+ Client * mongo.Client
132
+ // fpClient *mongo.Client
133
+ DB * mongo.Database
134
+ Coll * mongo.Collection
135
135
}
136
136
137
137
func newT (wrapped * testing.T , opts ... * Options ) * T {
@@ -176,17 +176,10 @@ func New(wrapped *testing.T, opts ...*Options) *T {
176
176
177
177
t := newT (wrapped , opts ... )
178
178
179
- // fpOpt := t.clientOpts
180
- // if fpOpt != nil {
181
- // fpOpt.AutoEncryptionOptions = nil
182
- // }
183
- // t.fpClient = t.createTestClient(fpOpt)
184
-
185
179
// only create a client if it needs to be shared in sub-tests
186
180
// otherwise, a new client will be created for each subtest
187
181
if t .shareClient != nil && * t .shareClient {
188
- t .fpClient = t .createTestClient (t .clientOpts )
189
- t .Client = t .createTestClient (t .clientOpts )
182
+ t .createTestClient ()
190
183
}
191
184
192
185
wrapped .Cleanup (t .cleanup )
@@ -209,7 +202,7 @@ func (t *T) cleanup() {
209
202
210
203
// always disconnect the client regardless of clientType because Client.Disconnect will work against
211
204
// all deployments
212
- _ = t .fpClient .Disconnect (context .Background ())
205
+ // _ = t.fpClient.Disconnect(context.Background())
213
206
_ = t .Client .Disconnect (context .Background ())
214
207
}
215
208
@@ -233,23 +226,15 @@ func (t *T) RunOpts(name string, opts *Options, callback func(mt *T)) {
233
226
sub .AddMockResponses (sub .mockResponses ... )
234
227
}
235
228
236
- // if sub.fpClient == nil {
237
- // clientOpts := sub.clientOpts
238
- // if clientOpts != nil {
239
- // clientOpts.AutoEncryptionOptions = nil
240
- // }
241
- // sub.fpClient = sub.createTestClient(clientOpts)
242
- // }
243
229
// for shareClient, inherit the client from the parent
244
230
if sub .shareClient != nil && * sub .shareClient && sub .clientType == t .clientType {
245
- sub .fpClient = t .fpClient
231
+ // sub.fpClient = t.fpClient
246
232
sub .Client = t .Client
247
233
}
248
234
// only create a client if not already set
249
235
if sub .Client == nil {
250
236
if sub .createClient == nil || * sub .createClient {
251
- sub .fpClient = sub .createTestClient (sub .clientOpts )
252
- sub .Client = sub .createTestClient (sub .clientOpts )
237
+ sub .createTestClient ()
253
238
}
254
239
}
255
240
// create a collection for this test
@@ -274,7 +259,7 @@ func (t *T) RunOpts(name string, opts *Options, callback func(mt *T)) {
274
259
}
275
260
// only disconnect client if it's not being shared
276
261
if sub .shareClient == nil || ! * sub .shareClient {
277
- _ = sub .fpClient .Disconnect (context .Background ())
262
+ // _ = sub.fpClient.Disconnect(context.Background())
278
263
_ = sub .Client .Disconnect (context .Background ())
279
264
}
280
265
assert .Equal (sub , 0 , sessions , "%v sessions checked out" , sessions )
@@ -424,10 +409,9 @@ func (t *T) ResetClient(opts *options.ClientOptions) {
424
409
t .clientOpts = opts
425
410
}
426
411
427
- _ = t .fpClient .Disconnect (context .Background ())
412
+ // _ = t.fpClient.Disconnect(context.Background())
428
413
_ = t .Client .Disconnect (context .Background ())
429
- t .fpClient = t .createTestClient (t .clientOpts )
430
- t .Client = t .createTestClient (t .clientOpts )
414
+ t .createTestClient ()
431
415
t .DB = t .Client .Database (t .dbName )
432
416
t .Coll = t .DB .Collection (t .collName , t .collOpts )
433
417
@@ -619,8 +603,6 @@ func (t *T) ClearFailPoints() {
619
603
}
620
604
}
621
605
t .failPointNames = t .failPointNames [:0 ]
622
- // t.fpClient.Disconnect(context.Background())
623
- // t.fpClient = nil
624
606
}
625
607
626
608
// CloneDatabase modifies the default database for this test to match the given options.
@@ -648,10 +630,14 @@ func sanitizeCollectionName(db string, coll string) string {
648
630
return coll
649
631
}
650
632
651
- func (t * T ) createTestClient (clientOpts * options.ClientOptions ) * mongo.Client {
652
- if clientOpts == nil {
633
+ func (t * T ) createTestClient () {
634
+ var clientOpts * options.ClientOptions
635
+ if t .clientOpts == nil {
653
636
// default opts
654
637
clientOpts = options .Client ().SetWriteConcern (MajorityWc ).SetReadPreference (PrimaryRp )
638
+ } else {
639
+ opts := * t .clientOpts
640
+ clientOpts = & opts
655
641
}
656
642
// set ServerAPIOptions to latest version if required
657
643
if clientOpts .Deployment == nil && t .clientType != Mock && clientOpts .ServerAPIOptions == nil && testContext .requireAPIVersion {
@@ -706,20 +692,17 @@ func (t *T) createTestClient(clientOpts *options.ClientOptions) *mongo.Client {
706
692
})
707
693
}
708
694
709
- var client * mongo.Client
710
- var err error
695
+ var uriOpts * options.ClientOptions
711
696
switch t .clientType {
712
697
case Pinned :
713
698
// pin to first mongos
714
699
pinnedHostList := []string {testContext .connString .Hosts [0 ]}
715
- uriOpts := options .Client ().ApplyURI (testContext .connString .Original ).SetHosts (pinnedHostList )
716
- client , err = mongo .NewClient (uriOpts , clientOpts )
700
+ uriOpts = options .Client ().ApplyURI (testContext .connString .Original ).SetHosts (pinnedHostList )
717
701
case Mock :
718
702
// clear pool monitor to avoid configuration error
719
703
clientOpts .PoolMonitor = nil
720
704
t .mockDeployment = newMockDeployment ()
721
705
clientOpts .Deployment = t .mockDeployment
722
- client , err = mongo .NewClient (clientOpts )
723
706
case Proxy :
724
707
t .proxyDialer = newProxyDialer ()
725
708
clientOpts .SetDialer (t .proxyDialer )
@@ -729,23 +712,21 @@ func (t *T) createTestClient(clientOpts *options.ClientOptions) *mongo.Client {
729
712
case Default :
730
713
// Use a different set of options to specify the URI because clientOpts may already have a URI or host seedlist
731
714
// specified.
732
- var uriOpts * options.ClientOptions
733
715
if clientOpts .Deployment == nil {
734
716
// Only specify URI if the deployment is not set to avoid setting topology/server options along with the
735
717
// deployment.
736
718
uriOpts = options .Client ().ApplyURI (testContext .connString .Original )
737
719
}
738
-
739
- // Pass in uriOpts first so clientOpts wins if there are any conflicting settings.
740
- client , err = mongo .NewClient (uriOpts , clientOpts )
741
720
}
721
+ var err error
722
+ // Pass in uriOpts first so clientOpts wins if there are any conflicting settings.
723
+ t .Client , err = mongo .NewClient (uriOpts , clientOpts )
742
724
if err != nil {
743
725
t .Fatalf ("error creating client: %v" , err )
744
726
}
745
- if err := client .Connect (context .Background ()); err != nil {
727
+ if err := t . Client .Connect (context .Background ()); err != nil {
746
728
t .Fatalf ("error connecting client: %v" , err )
747
729
}
748
- return client
749
730
}
750
731
751
732
func (t * T ) createTestCollection () {
0 commit comments