Skip to content

Commit 3bc01fb

Browse files
committed
updates
1 parent 0fd670e commit 3bc01fb

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

mongo/integration/mtest/mongotest.go

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ type WriteConcernErrorData struct {
8484
ErrInfo bson.Raw `bson:"errInfo,omitempty"`
8585
}
8686

87+
type failPoint struct {
88+
name string
89+
clientOpts *options.ClientOptions
90+
}
91+
8792
// T is a wrapper around testing.T.
8893
type T struct {
8994
// connsCheckedOut is the net number of connections checked out during test execution.
@@ -103,7 +108,7 @@ type T struct {
103108
createdColls []*Collection // collections created in this test
104109
proxyDialer *proxyDialer
105110
dbName, collName string
106-
failPointNames []string
111+
failPointNames []failPoint
107112
minServerVersion string
108113
maxServerVersion string
109114
validTopologies []TopologyKind
@@ -129,9 +134,8 @@ type T struct {
129134
failed []*event.CommandFailedEvent
130135

131136
Client *mongo.Client
132-
// fpClient *mongo.Client
133-
DB *mongo.Database
134-
Coll *mongo.Collection
137+
DB *mongo.Database
138+
Coll *mongo.Collection
135139
}
136140

137141
func newT(wrapped *testing.T, opts ...*Options) *T {
@@ -227,7 +231,6 @@ func (t *T) RunOpts(name string, opts *Options, callback func(mt *T)) {
227231

228232
// for shareClient, inherit the client from the parent
229233
if sub.shareClient != nil && *sub.shareClient && sub.clientType == t.clientType {
230-
// sub.fpClient = t.fpClient
231234
sub.Client = t.Client
232235
}
233236
// only create a client if not already set
@@ -564,7 +567,8 @@ func (t *T) SetFailPoint(fp FailPoint) {
564567
if err := SetFailPoint(fp, t.Client); err != nil {
565568
t.Fatal(err)
566569
}
567-
t.failPointNames = append(t.failPointNames, fp.ConfigureFailPoint)
570+
clientOpts := *t.clientOpts
571+
t.failPointNames = append(t.failPointNames, failPoint{fp.ConfigureFailPoint, &clientOpts})
568572
}
569573

570574
// 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) {
577581
}
578582

579583
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})
581586
}
582587

583588
// TrackFailPoint adds the given fail point to the list of fail points to be disabled when the current test finishes.
584589
// This function does not create a fail point on the server.
585590
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})
587593
}
588594

589595
// ClearFailPoints disables all previously set failpoints for this test.
590596
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)
597599
if err != nil {
598600
t.Fatalf("error creating client: %v", err)
599601
}
@@ -603,16 +605,13 @@ func (t *T) ClearFailPoints() {
603605
defer func() {
604606
_ = client.Disconnect(context.Background())
605607
}()
606-
}
607-
db := client.Database("admin")
608-
for _, fp := range t.failPointNames {
609608
cmd := bson.D{
610-
{"configureFailPoint", fp},
609+
{"configureFailPoint", fp.name},
611610
{"mode", "off"},
612611
}
613-
err = db.RunCommand(context.Background(), cmd).Err()
612+
err = client.Database("admin").RunCommand(context.Background(), cmd).Err()
614613
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)
616615
}
617616
}
618617
t.failPointNames = t.failPointNames[:0]
@@ -739,15 +738,6 @@ func (t *T) createTestClient() {
739738
if err := t.Client.Connect(context.Background()); err != nil {
740739
t.Fatalf("error connecting client: %v", err)
741740
}
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-
// }
751741
}
752742

753743
func (t *T) createTestCollection() {

0 commit comments

Comments
 (0)