Skip to content

test(NODE-2856): Check that defaultTransactionOptions get used from session #2845

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

40 changes: 40 additions & 0 deletions test/functional/readpreference.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,44 @@ describe('ReadPreference', function() {
});
})
});

describe('Session readPreference', function() {
let client;
let session;

beforeEach(function(done) {
let configuration = this.configuration;
client = configuration.newClient(configuration.writeConcernMax(), {
readPreference: 'primaryPreferred'
});
client.connect(err => {
done(err);
});
});

afterEach(function(done) {
if (session) {
session.abortTransaction(() => {
session.endSession(() => {
client.close(() => done());
});
});
} else {
client.close(() => done());
}
});

it('should use session readPreference instead of client readPreference', {
metadata: { requires: { unifiedTopology: true, topology: ['single', 'replicaset'] } },
test: function() {
session = client.startSession({
defaultTransactionOptions: { readPreference: 'secondary' },
causalConsistency: true
});
session.startTransaction();
const result = ReadPreference.resolve(client, { session: session });
expect(result).to.have.property('mode', 'secondary');
}
});
});
});