@@ -84,6 +84,11 @@ type WriteConcernErrorData struct {
84
84
ErrInfo bson.Raw `bson:"errInfo,omitempty"`
85
85
}
86
86
87
+ type failPoint struct {
88
+ name string
89
+ clientOpts * options.ClientOptions
90
+ }
91
+
87
92
// T is a wrapper around testing.T.
88
93
type T struct {
89
94
// connsCheckedOut is the net number of connections checked out during test execution.
@@ -103,7 +108,7 @@ type T struct {
103
108
createdColls []* Collection // collections created in this test
104
109
proxyDialer * proxyDialer
105
110
dbName , collName string
106
- failPointNames []string
111
+ failPointNames []failPoint
107
112
minServerVersion string
108
113
maxServerVersion string
109
114
validTopologies []TopologyKind
@@ -129,9 +134,8 @@ type T struct {
129
134
failed []* event.CommandFailedEvent
130
135
131
136
Client * mongo.Client
132
- // fpClient *mongo.Client
133
- DB * mongo.Database
134
- Coll * mongo.Collection
137
+ DB * mongo.Database
138
+ Coll * mongo.Collection
135
139
}
136
140
137
141
func newT (wrapped * testing.T , opts ... * Options ) * T {
@@ -227,7 +231,6 @@ func (t *T) RunOpts(name string, opts *Options, callback func(mt *T)) {
227
231
228
232
// for shareClient, inherit the client from the parent
229
233
if sub .shareClient != nil && * sub .shareClient && sub .clientType == t .clientType {
230
- // sub.fpClient = t.fpClient
231
234
sub .Client = t .Client
232
235
}
233
236
// only create a client if not already set
@@ -564,7 +567,8 @@ func (t *T) SetFailPoint(fp FailPoint) {
564
567
if err := SetFailPoint (fp , t .Client ); err != nil {
565
568
t .Fatal (err )
566
569
}
567
- t .failPointNames = append (t .failPointNames , fp .ConfigureFailPoint )
570
+ clientOpts := * t .clientOpts
571
+ t .failPointNames = append (t .failPointNames , failPoint {fp .ConfigureFailPoint , & clientOpts })
568
572
}
569
573
570
574
// SetFailPointFromDocument sets the fail point represented by the given document for the client associated with T. This
@@ -577,23 +581,21 @@ func (t *T) SetFailPointFromDocument(fp bson.Raw) {
577
581
}
578
582
579
583
name := fp .Index (0 ).Value ().StringValue ()
580
- t .failPointNames = append (t .failPointNames , name )
584
+ clientOpts := * t .clientOpts
585
+ t .failPointNames = append (t .failPointNames , failPoint {name , & clientOpts })
581
586
}
582
587
583
588
// TrackFailPoint adds the given fail point to the list of fail points to be disabled when the current test finishes.
584
589
// This function does not create a fail point on the server.
585
590
func (t * T ) TrackFailPoint (fpName string ) {
586
- t .failPointNames = append (t .failPointNames , fpName )
591
+ clientOpts := * t .clientOpts
592
+ t .failPointNames = append (t .failPointNames , failPoint {fpName , & clientOpts })
587
593
}
588
594
589
595
// ClearFailPoints disables all previously set failpoints for this test.
590
596
func (t * T ) ClearFailPoints () {
591
- var err error
592
- client := t .Client
593
- if t .clientOpts .AutoEncryptionOptions != nil {
594
- clientOpts := * t .clientOpts
595
- clientOpts .AutoEncryptionOptions = nil
596
- client , err = mongo .NewClient (& clientOpts )
597
+ for _ , fp := range t .failPointNames {
598
+ client , err := mongo .NewClient (fp .clientOpts )
597
599
if err != nil {
598
600
t .Fatalf ("error creating client: %v" , err )
599
601
}
@@ -603,16 +605,13 @@ func (t *T) ClearFailPoints() {
603
605
defer func () {
604
606
_ = client .Disconnect (context .Background ())
605
607
}()
606
- }
607
- db := client .Database ("admin" )
608
- for _ , fp := range t .failPointNames {
609
608
cmd := bson.D {
610
- {"configureFailPoint" , fp },
609
+ {"configureFailPoint" , fp . name },
611
610
{"mode" , "off" },
612
611
}
613
- err = db .RunCommand (context .Background (), cmd ).Err ()
612
+ err = client . Database ( "admin" ) .RunCommand (context .Background (), cmd ).Err ()
614
613
if err != nil {
615
- t .Fatalf ("error clearing fail point %s: %v" , fp , err )
614
+ t .Fatalf ("error clearing fail point %s: %v" , fp . name , err )
616
615
}
617
616
}
618
617
t .failPointNames = t .failPointNames [:0 ]
@@ -739,15 +738,6 @@ func (t *T) createTestClient() {
739
738
if err := t .Client .Connect (context .Background ()); err != nil {
740
739
t .Fatalf ("error connecting client: %v" , err )
741
740
}
742
-
743
- // clientOpts.AutoEncryptionOptions = nil
744
- // t.fpClient, err = mongo.NewClient(uriOpts, clientOpts)
745
- // if err != nil {
746
- // t.Fatalf("error creating client: %v", err)
747
- // }
748
- // if err := t.fpClient.Connect(context.Background()); err != nil {
749
- // t.Fatalf("error connecting client: %v", err)
750
- // }
751
741
}
752
742
753
743
func (t * T ) createTestCollection () {
0 commit comments