Skip to content

Commit 6ca8e2d

Browse files
GODRIVER-2277 Remove causal consistency prose test #10 (#879)
* GODRIVER-2277 Remove causal consistency prose test #10 * GODRIVER-2277 Remove causal consistency prose test no. 10 * add unack writes subtest to TestSessions * couple assertion and msg * use non-verbose error handling * allow error reassignment * make assert msg more verbose * clean up assert msg
1 parent 0a65aaa commit 6ca8e2d

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

mongo/integration/causal_consistency_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
1818
"go.mongodb.org/mongo-driver/mongo/options"
1919
"go.mongodb.org/mongo-driver/mongo/readconcern"
20-
"go.mongodb.org/mongo-driver/mongo/writeconcern"
2120
)
2221

2322
// set of operations that support read concerns taken from read/write concern spec.
@@ -193,21 +192,6 @@ func TestCausalConsistency_Supported(t *testing.T) {
193192
assert.NotNil(mt, sentOptime, "expected operation time on command, got nil")
194193
assert.True(mt, currOptime.Equal(*sentOptime), "expected operation time %v, got %v", currOptime, sentOptime)
195194
})
196-
unackWcOpts := options.Collection().SetWriteConcern(writeconcern.New(writeconcern.W(0)))
197-
mt.RunOpts("unacknowledged write", mtest.NewOptions().CollectionOptions(unackWcOpts), func(mt *mtest.T) {
198-
// unacknowledged write should not update the operationTime of a session
199-
200-
sess, err := mt.Client.StartSession()
201-
assert.Nil(mt, err, "StartSession error: %v", err)
202-
defer sess.EndSession(context.Background())
203-
204-
_ = mongo.WithSession(context.Background(), sess, func(sc mongo.SessionContext) error {
205-
_, _ = mt.Coll.InsertOne(sc, bson.D{{"x", 1}})
206-
return nil
207-
})
208-
optime := sess.OperationTime()
209-
assert.Nil(mt, optime, "expected operation time nil, got %v", optime)
210-
})
211195
mt.Run("clusterTime included", func(mt *mtest.T) {
212196
// $clusterTime should be included in commands if the deployment supports cluster times
213197

mongo/integration/sessions_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
2121
"go.mongodb.org/mongo-driver/mongo/options"
2222
"go.mongodb.org/mongo-driver/mongo/readpref"
23+
"go.mongodb.org/mongo-driver/mongo/writeconcern"
2324
"go.mongodb.org/mongo-driver/x/mongo/driver/session"
2425
)
2526

@@ -341,6 +342,22 @@ func TestSessions(t *testing.T) {
341342
assertCollectionCount(mt, int64(numDocs))
342343
})
343344
})
345+
346+
unackWcOpts := options.Collection().SetWriteConcern(writeconcern.New(writeconcern.W(0)))
347+
mt.RunOpts("unacknowledged write", mtest.NewOptions().CollectionOptions(unackWcOpts), func(mt *mtest.T) {
348+
// unacknowledged write during a session should result in an error
349+
sess, err := mt.Client.StartSession()
350+
assert.Nil(mt, err, "StartSession error: %v", err)
351+
defer sess.EndSession(context.Background())
352+
353+
err = mongo.WithSession(context.Background(), sess, func(sc mongo.SessionContext) error {
354+
_, err := mt.Coll.InsertOne(sc, bson.D{{"x", 1}})
355+
return err
356+
})
357+
358+
assert.Equal(mt, err, mongo.ErrUnacknowledgedWrite,
359+
"expected ErrUnacknowledgedWrite on unacknowledged write in session, got %v", err)
360+
})
344361
}
345362

346363
func assertCollectionCount(mt *mtest.T, expectedCount int64) {

0 commit comments

Comments
 (0)