Skip to content

Commit

Permalink
test(NODE-2856): ensure defaultTransactionOptions get used from sessi…
Browse files Browse the repository at this point in the history
…on (#2845)
  • Loading branch information
W-A-James authored Jun 22, 2021
1 parent 8c8b4c3 commit 68b4665
Showing 1 changed file with 40 additions and 0 deletions.
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');
}
});
});
});

0 comments on commit 68b4665

Please sign in to comment.