Files
mongo/jstests/core/txns/basic_causal_consistency.js
Joseph Prince d04dc10cac SERVER-82311 rename test tag
GitOrigin-RevId: 598fb15a21c0c4e53ef47a4b5c5dc6f5ae5fd5ed
2023-12-14 06:03:22 +00:00

44 lines
1.6 KiB
JavaScript

// Test that the shell helper supports causal consistency.
//
// @tags: [
// # The test runs commands that are not allowed with security token: endSession.
// not_allowed_with_signed_security_token,
// uses_transactions,
// uses_snapshot_read_concern
// ]
// TODO (SERVER-39704): Remove the following load after SERVER-39704 is completed
import {withTxnAndAutoRetryOnMongos} from "jstests/libs/auto_retry_transaction_in_sharding.js";
const dbName = "test";
const collName = "basic_causal_consistency";
const testDB = db.getSiblingDB(dbName);
testDB.runCommand({drop: collName, writeConcern: {w: "majority"}});
assert.commandWorked(testDB.runCommand({create: collName, writeConcern: {w: "majority"}}));
const sessionOptions = {
causalConsistency: true
};
const session = testDB.getMongo().startSession(sessionOptions);
const sessionDb = session.getDatabase(dbName);
const sessionColl = sessionDb.getCollection(collName);
// TODO (SERVER-39704): We use the withTxnAndAutoRetryOnMongos
// function to handle how MongoS will propagate a StaleShardVersion error as a
// TransientTransactionError. After SERVER-39704 is completed the
// withTxnAndAutoRetryOnMongos function can be removed
withTxnAndAutoRetryOnMongos(session, () => {
// Performing a read first should work when snapshot readConcern is specified.
assert.docEq(null, sessionColl.findOne({_id: "insert-1"}));
assert.commandWorked(sessionColl.insert({_id: "insert-1"}));
assert.docEq(null, sessionColl.findOne({_id: "insert-2"}));
assert.docEq({_id: "insert-1"}, sessionColl.findOne({_id: "insert-1"}));
});
session.endSession();