Skip to content

Commit

Permalink
test: add tests to ensure readPreference and writeConcern are respect…
Browse files Browse the repository at this point in the history
…ed from uri (#2715)

NODE-2965
  • Loading branch information
emadum authored and ljhaywar committed Nov 9, 2021
1 parent 24b52c2 commit a2ac0ed
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
29 changes: 28 additions & 1 deletion test/functional/readpreference.test.js
Expand Up @@ -3,9 +3,11 @@
const test = require('./shared').assert;
const setupDatabase = require('./shared').setupDatabase;
const withMonitoredClient = require('./shared').withMonitoredClient;
const expect = require('chai').expect;
const { ReadPreference, Topology } = require('../../src');
const { withClient } = require('./shared');
const chai = require('chai');
chai.use(require('chai-subset'));
const expect = chai.expect;

describe('ReadPreference', function () {
before(function () {
Expand Down Expand Up @@ -620,4 +622,29 @@ describe('ReadPreference', function () {
});
});
});

it('should respect readPreference from uri', {
metadata: { requires: { topology: 'replicaset', mongodb: '>=3.6' } },
test: withMonitoredClient('find', { queryOptions: { readPreference: 'secondary' } }, function (
client,
events,
done
) {
expect(client.readPreference.mode).to.equal('secondary');
client
.db('test')
.collection('test')
.findOne({ a: 1 }, err => {
expect(err).to.not.exist;
expect(events).to.be.an('array').with.lengthOf(1);
expect(events[0]).to.containSubset({
commandName: 'find',
command: {
$readPreference: { mode: 'secondary' }
}
});
done();
});
})
});
});
22 changes: 22 additions & 0 deletions test/functional/write_concern.test.js
Expand Up @@ -23,6 +23,28 @@ describe('Write Concern', function () {
generateTopologyTests(testSuites, testContext);
});

it(
'should respect writeConcern from uri',
withMonitoredClient('insert', { queryOptions: { w: 0 } }, function (client, events, done) {
expect(client.writeConcern).to.eql({ w: 0 });
client
.db('test')
.collection('test')
.insertOne({ a: 1 }, (err, result) => {
expect(err).to.not.exist;
expect(result).to.exist;
expect(events).to.be.an('array').with.lengthOf(1);
expect(events[0]).to.containSubset({
commandName: 'insert',
command: {
writeConcern: { w: 0 }
}
});
done();
});
})
);

// TODO: once `read-write-concern/connection-string` spec tests are implemented these can likely be removed
describe('test journal connection string option', function () {
function journalOptionTest(client, events, done) {
Expand Down

0 comments on commit a2ac0ed

Please sign in to comment.