Skip to content

Commit 68b4665

Browse files
authored
test(NODE-2856): ensure defaultTransactionOptions get used from session (#2845)
1 parent 8c8b4c3 commit 68b4665

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/functional/readpreference.test.js

+40
Original file line numberDiff line numberDiff line change
@@ -759,4 +759,44 @@ describe('ReadPreference', function() {
759759
});
760760
})
761761
});
762+
763+
describe('Session readPreference', function() {
764+
let client;
765+
let session;
766+
767+
beforeEach(function(done) {
768+
let configuration = this.configuration;
769+
client = configuration.newClient(configuration.writeConcernMax(), {
770+
readPreference: 'primaryPreferred'
771+
});
772+
client.connect(err => {
773+
done(err);
774+
});
775+
});
776+
777+
afterEach(function(done) {
778+
if (session) {
779+
session.abortTransaction(() => {
780+
session.endSession(() => {
781+
client.close(() => done());
782+
});
783+
});
784+
} else {
785+
client.close(() => done());
786+
}
787+
});
788+
789+
it('should use session readPreference instead of client readPreference', {
790+
metadata: { requires: { unifiedTopology: true, topology: ['single', 'replicaset'] } },
791+
test: function() {
792+
session = client.startSession({
793+
defaultTransactionOptions: { readPreference: 'secondary' },
794+
causalConsistency: true
795+
});
796+
session.startTransaction();
797+
const result = ReadPreference.resolve(client, { session: session });
798+
expect(result).to.have.property('mode', 'secondary');
799+
}
800+
});
801+
});
762802
});

0 commit comments

Comments
 (0)