From bdc4bf6832682580511c237fc4fa2ce4c2b4c90f Mon Sep 17 00:00:00 2001 From: "mongodb-dbx-release-bot[bot]" <167856002+mongodb-dbx-release-bot[bot]@users.noreply.github.com> Date: Wed, 18 Sep 2024 12:41:02 +0000 Subject: [PATCH 1/3] BUMP v2.0.0-beta2 Signed-off-by: mongodb-dbx-release-bot[bot] <167856002+mongodb-dbx-release-bot[bot]@users.noreply.github.com> --- version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version/version.go b/version/version.go index 254dc4e196..692a904492 100644 --- a/version/version.go +++ b/version/version.go @@ -8,4 +8,4 @@ package version // import "go.mongodb.org/mongo-driver/version" // Driver is the current version of the driver. -var Driver = "2.0.0-beta1" +var Driver = "2.0.0-beta2" From 251c7323742c733bf7421835c652d032b77079f1 Mon Sep 17 00:00:00 2001 From: Joy Wang <49984055+joyjwang@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:48:31 -0400 Subject: [PATCH 2/3] GODRIVER-3332 Returning ErrClientDisconnected when sessionPool is null is unecessary (#1807) --- mongo/client.go | 12 ------------ mongo/client_test.go | 15 ++++++++------- mongo/collection_test.go | 13 +++++++++++-- mongo/database_test.go | 14 ++++++++++---- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/mongo/client.go b/mongo/client.go index c9859eff23..d7dc15fcc7 100644 --- a/mongo/client.go +++ b/mongo/client.go @@ -396,10 +396,6 @@ func (c *Client) Ping(ctx context.Context, rp *readpref.ReadPref) error { // If the DefaultReadConcern, DefaultWriteConcern, or DefaultReadPreference options are not set, the client's read // concern, write concern, or read preference will be used, respectively. func (c *Client) StartSession(opts ...options.Lister[options.SessionOptions]) (*Session, error) { - if c.sessionPool == nil { - return nil, ErrClientDisconnected - } - sessArgs, err := mongoutil.NewOptions(opts...) if err != nil { return nil, err @@ -454,10 +450,6 @@ func (c *Client) StartSession(opts ...options.Lister[options.SessionOptions]) (* } func (c *Client) endSessions(ctx context.Context) { - if c.sessionPool == nil { - return - } - sessionIDs := c.sessionPool.IDSlice() op := operation.NewEndSessions(nil).ClusterClock(c.clock).Deployment(c.deployment). ServerSelector(&serverselector.ReadPref{ReadPref: readpref.PrimaryPreferred()}). @@ -872,10 +864,6 @@ func (c *Client) UseSessionWithOptions( // documentation). func (c *Client) Watch(ctx context.Context, pipeline interface{}, opts ...options.Lister[options.ChangeStreamOptions]) (*ChangeStream, error) { - if c.sessionPool == nil { - return nil, ErrClientDisconnected - } - csConfig := changeStreamConfig{ readConcern: c.readConcern, readPreference: c.readPreference, diff --git a/mongo/client_test.go b/mongo/client_test.go index 72e3ee0962..70e2075124 100644 --- a/mongo/client_test.go +++ b/mongo/client_test.go @@ -19,13 +19,13 @@ import ( "go.mongodb.org/mongo-driver/v2/internal/assert" "go.mongodb.org/mongo-driver/v2/internal/integtest" "go.mongodb.org/mongo-driver/v2/internal/mongoutil" + "go.mongodb.org/mongo-driver/v2/internal/require" "go.mongodb.org/mongo-driver/v2/mongo/options" "go.mongodb.org/mongo-driver/v2/mongo/readconcern" "go.mongodb.org/mongo-driver/v2/mongo/readpref" "go.mongodb.org/mongo-driver/v2/mongo/writeconcern" "go.mongodb.org/mongo-driver/v2/tag" "go.mongodb.org/mongo-driver/v2/x/mongo/driver/mongocrypt" - "go.mongodb.org/mongo-driver/v2/x/mongo/driver/session" "go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology" ) @@ -37,7 +37,7 @@ func setupClient(opts ...options.Lister[options.ClientOptions]) *Client { integtest.AddTestServerAPIVersion(clientOpts) opts = append(opts, clientOpts) } - client, _ := newClient(opts...) + client, _ := Connect(opts...) return client } @@ -53,11 +53,14 @@ func TestClient(t *testing.T) { assert.Equal(t, dbName, db.Name(), "expected db name %v, got %v", dbName, db.Name()) assert.Equal(t, client, db.Client(), "expected client %v, got %v", client, db.Client()) }) - t.Run("replace topology error", func(t *testing.T) { + t.Run("replaceErrors for disconnected topology", func(t *testing.T) { client := setupClient() - _, err := client.StartSession() - assert.Equal(t, ErrClientDisconnected, err, "expected error %v, got %v", ErrClientDisconnected, err) + topo, ok := client.deployment.(*topology.Topology) + require.True(t, ok, "client deployment is not a topology") + + err := topo.Disconnect(context.Background()) + require.NoError(t, err) _, err = client.ListDatabases(bgCtx, bson.D{}) assert.Equal(t, ErrClientDisconnected, err, "expected error %v, got %v", ErrClientDisconnected, err) @@ -72,9 +75,7 @@ func TestClient(t *testing.T) { assert.Equal(t, ErrClientDisconnected, err, "expected error %v, got %v", ErrClientDisconnected, err) }) t.Run("nil document error", func(t *testing.T) { - // manually set session pool to non-nil because Watch will return ErrClientDisconnected client := setupClient() - client.sessionPool = &session.Pool{} _, err := client.Watch(bgCtx, nil) watchErr := errors.New("can only marshal slices and arrays into aggregation pipelines, but got invalid") diff --git a/mongo/collection_test.go b/mongo/collection_test.go index 648f04a46f..268f1c8c0e 100644 --- a/mongo/collection_test.go +++ b/mongo/collection_test.go @@ -8,17 +8,20 @@ package mongo import ( "bytes" + "context" "errors" "testing" "go.mongodb.org/mongo-driver/v2/bson" "go.mongodb.org/mongo-driver/v2/internal/assert" "go.mongodb.org/mongo-driver/v2/internal/ptrutil" + "go.mongodb.org/mongo-driver/v2/internal/require" "go.mongodb.org/mongo-driver/v2/mongo/options" "go.mongodb.org/mongo-driver/v2/mongo/readconcern" "go.mongodb.org/mongo-driver/v2/mongo/readpref" "go.mongodb.org/mongo-driver/v2/mongo/writeconcern" "go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore" + "go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology" ) const ( @@ -78,12 +81,18 @@ func TestCollection(t *testing.T) { } compareColls(t, expected, coll) }) - t.Run("replace topology error", func(t *testing.T) { + t.Run("replaceErrors for disconnected topology", func(t *testing.T) { coll := setupColl("foo") doc := bson.D{} update := bson.D{{"$update", bson.D{{"x", 1}}}} - _, err := coll.InsertOne(bgCtx, doc) + topo, ok := coll.client.deployment.(*topology.Topology) + require.True(t, ok, "client deployment is not a topology") + + err := topo.Disconnect(context.Background()) + require.NoError(t, err) + + _, err = coll.InsertOne(bgCtx, doc) assert.Equal(t, ErrClientDisconnected, err, "expected error %v, got %v", ErrClientDisconnected, err) _, err = coll.InsertMany(bgCtx, []interface{}{doc}) diff --git a/mongo/database_test.go b/mongo/database_test.go index 6b9b8df319..0c324b9b09 100644 --- a/mongo/database_test.go +++ b/mongo/database_test.go @@ -14,6 +14,7 @@ import ( "go.mongodb.org/mongo-driver/v2/bson" "go.mongodb.org/mongo-driver/v2/internal/assert" + "go.mongodb.org/mongo-driver/v2/internal/require" "go.mongodb.org/mongo-driver/v2/mongo/options" "go.mongodb.org/mongo-driver/v2/mongo/readconcern" "go.mongodb.org/mongo-driver/v2/mongo/readpref" @@ -83,9 +84,16 @@ func TestDatabase(t *testing.T) { compareDbs(t, expected, got) }) }) - t.Run("replace topology error", func(t *testing.T) { + t.Run("replaceErrors for disconnected topology", func(t *testing.T) { db := setupDb("foo") - err := db.RunCommand(bgCtx, bson.D{{"x", 1}}).Err() + + topo, ok := db.client.deployment.(*topology.Topology) + require.True(t, ok, "client deployment is not a topology") + + err := topo.Disconnect(context.Background()) + require.NoError(t, err) + + err = db.RunCommand(bgCtx, bson.D{{"x", 1}}).Err() assert.Equal(t, ErrClientDisconnected, err, "expected error %v, got %v", ErrClientDisconnected, err) err = db.Drop(bgCtx) @@ -96,9 +104,7 @@ func TestDatabase(t *testing.T) { }) t.Run("TransientTransactionError label", func(t *testing.T) { client := setupClient(options.Client().ApplyURI("mongodb://nonexistent").SetServerSelectionTimeout(3 * time.Second)) - err := client.connect() defer func() { _ = client.Disconnect(bgCtx) }() - assert.Nil(t, err, "expected nil, got %v", err) t.Run("negative case of non-transaction", func(t *testing.T) { var sse topology.ServerSelectionError From ce00395974c83c7325470b268be8c82e7f34cd71 Mon Sep 17 00:00:00 2001 From: Joy Wang <49984055+joyjwang@users.noreply.github.com> Date: Fri, 20 Sep 2024 09:36:07 -0400 Subject: [PATCH 3/3] GODRIVER-2529 Remove repeat test from client_encryption_test.go (#1822) --- mongo/client_encryption_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/mongo/client_encryption_test.go b/mongo/client_encryption_test.go index 35acedb5b2..1c49b3f707 100644 --- a/mongo/client_encryption_test.go +++ b/mongo/client_encryption_test.go @@ -32,7 +32,6 @@ func TestClientEncryption_ErrClientDisconnected(t *testing.T) { t.Run("CreateEncryptedCollection", func(t *testing.T) { t.Parallel() _, _, err := ce.CreateEncryptedCollection(context.Background(), nil, "", options.CreateCollection(), "", nil) - assert.Equal(t, ErrClientDisconnected, err, "expected error %v, got %v", ErrClientDisconnected, err) assert.ErrorIs(t, err, ErrClientDisconnected) }) t.Run("AddKeyAltName", func(t *testing.T) {