Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 5 additions & 23 deletions internal/integration/mtest/mongotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ type T struct {
clientType ClientType
clientOpts *options.ClientOptions
collOpts *options.CollectionOptionsBuilder
shareClient *bool
allowFailPointsOnSharded bool

baseOpts *Options // used to create subtests
Expand Down Expand Up @@ -122,9 +121,6 @@ func newT(wrapped *testing.T, opts ...*Options) *T {

// create a set of base options for sub-tests
t.baseOpts = NewOptions().ClientOptions(t.clientOpts).CollectionOptions(t.collOpts).ClientType(t.clientType)
if t.shareClient != nil {
t.baseOpts.ShareClient(*t.shareClient)
}
if t.allowFailPointsOnSharded {
t.baseOpts.AllowFailPointsOnSharded()
}
Expand All @@ -143,12 +139,6 @@ func New(wrapped *testing.T, opts ...*Options) *T {

t := newT(wrapped, opts...)

// only create a client if it needs to be shared in sub-tests
// otherwise, a new client will be created for each subtest
if t.shareClient != nil && *t.shareClient {
t.createTestClient()
}

wrapped.Cleanup(t.cleanup)

return t
Expand Down Expand Up @@ -192,16 +182,10 @@ func (t *T) RunOpts(name string, opts *Options, callback func(mt *T)) {
sub.AddMockResponses(sub.mockResponses...)
}

// for shareClient, inherit the client from the parent
if sub.shareClient != nil && *sub.shareClient && sub.clientType == t.clientType {
sub.Client = t.Client
}
// only create a client if not already set
if sub.Client == nil {
if sub.createClient == nil || *sub.createClient {
sub.createTestClient()
}
if sub.createClient == nil || *sub.createClient {
sub.createTestClient()
}

// create a collection for this test
if sub.Client != nil {
sub.createTestCollection()
Expand All @@ -222,10 +206,8 @@ func (t *T) RunOpts(name string, opts *Options, callback func(mt *T)) {
sub.ClearFailPoints()
sub.ClearCollections()
}
// only disconnect client if it's not being shared
if sub.shareClient == nil || !*sub.shareClient {
_ = sub.Client.Disconnect(context.Background())
}

_ = sub.Client.Disconnect(context.Background())
assert.Equal(sub, 0, sessions, "%v sessions checked out", sessions)
assert.Equal(sub, 0, conns, "%v connections checked out", conns)
}()
Expand Down
10 changes: 0 additions & 10 deletions internal/integration/mtest/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,6 @@ func (op *Options) CreateCollection(create bool) *Options {
return op
}

// ShareClient specifies whether or not a test should pass its client down to sub-tests. This should be set when calling
// New() if the inheriting behavior is desired. This option must not be used if the test accesses command monitoring
// events.
func (op *Options) ShareClient(share bool) *Options {
op.optFuncs = append(op.optFuncs, func(t *T) {
t.shareClient = &share
})
return op
}

// CollectionName specifies the name for the collection for the test.
func (op *Options) CollectionName(collName string) *Options {
op.optFuncs = append(op.optFuncs, func(t *T) {
Expand Down
Loading