From 8e0de1a8fa432f59dc934484bf26520d0ed2dfd9 Mon Sep 17 00:00:00 2001 From: Matt Dale <9760375+matthewdale@users.noreply.github.com> Date: Thu, 16 Oct 2025 16:14:05 -0700 Subject: [PATCH] Remove the unused and dangerous ShareClient mtest option. --- internal/integration/mtest/mongotest.go | 28 +++++-------------------- internal/integration/mtest/options.go | 10 --------- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/internal/integration/mtest/mongotest.go b/internal/integration/mtest/mongotest.go index 07c67a4ce0..8978189583 100644 --- a/internal/integration/mtest/mongotest.go +++ b/internal/integration/mtest/mongotest.go @@ -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 @@ -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() } @@ -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 @@ -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() @@ -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) }() diff --git a/internal/integration/mtest/options.go b/internal/integration/mtest/options.go index 565983a3d1..1533bde0da 100644 --- a/internal/integration/mtest/options.go +++ b/internal/integration/mtest/options.go @@ -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) {