Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emadum committed Jan 21, 2021
1 parent 85439d9 commit 4dbd767
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
36 changes: 28 additions & 8 deletions test/functional/readpreference.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ const Topology = require('../../lib/core/sdam/topology').Topology;
const test = require('./shared').assert;
const setupDatabase = require('./shared').setupDatabase;
const withMonitoredClient = require('./shared').withMonitoredClient;
const expect = require('chai').expect;

const ReadPreference = require('../../lib/core/topologies/read_preference');
const withClient = require('./shared').withClient;
const chai = require('chai');
chai.use(require('chai-subset'));
const expect = chai.expect;

describe('ReadPreference', function() {
before(function() {
Expand Down Expand Up @@ -730,13 +733,30 @@ describe('ReadPreference', function() {
});
});

it('should respect readPreference from uri', function(done) {
const configuration = this.configuration;
const client = configuration.newClient(`${configuration.url()}?readPreference=secondary`);
client.connect(err => {
expect(err).to.not.exist;
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.close(done);
});
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();
});
})
});
});
30 changes: 22 additions & 8 deletions test/functional/write_concern.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,29 @@ describe('Write Concern', function() {
generateTopologyTests(testSuites, testContext);
});

it('should respect writeConcern from uri', function(done) {
const configuration = this.configuration;
const client = configuration.newClient(`${configuration.url()}?w=0`);
client.connect(err => {
expect(err).to.not.exist;
it(
'should respect writeConcern from uri',
withMonitoredClient('insert', { queryOptions: { w: 0 } }, function(client, events, done) {
expect(client.writeConcern).to.eql({ w: 0 });
client.close(done);
});
});
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() {
Expand Down

0 comments on commit 4dbd767

Please sign in to comment.