Skip to content

Commit 2e868cc

Browse files
committed
improve tests
1 parent 85439d9 commit 2e868cc

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

test/functional/readpreference.test.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -730,13 +730,31 @@ describe('ReadPreference', function() {
730730
});
731731
});
732732

733-
it('should respect readPreference from uri', function(done) {
734-
const configuration = this.configuration;
735-
const client = configuration.newClient(`${configuration.url()}?readPreference=secondary`);
736-
client.connect(err => {
737-
expect(err).to.not.exist;
733+
it(
734+
'should respect readPreference from uri',
735+
withMonitoredClient('find', { queryOptions: { readPreference: 'secondary' } }, function(
736+
client,
737+
events,
738+
done
739+
) {
738740
expect(client.readPreference.mode).to.equal('secondary');
739-
client.close(done);
740-
});
741-
});
741+
client
742+
.db('test')
743+
.collection('test')
744+
.findOne({ a: 1 }, (err, result) => {
745+
expect(err).to.not.exist;
746+
expect(result).to.exist;
747+
expect(events)
748+
.to.be.an('array')
749+
.with.lengthOf(1);
750+
expect(events[0]).to.containSubset({
751+
commandName: 'find',
752+
command: {
753+
$readPreference: { mode: 'secondary' }
754+
}
755+
});
756+
done();
757+
});
758+
})
759+
);
742760
});

test/functional/write_concern.test.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,29 @@ describe('Write Concern', function() {
2121
generateTopologyTests(testSuites, testContext);
2222
});
2323

24-
it('should respect writeConcern from uri', function(done) {
25-
const configuration = this.configuration;
26-
const client = configuration.newClient(`${configuration.url()}?w=0`);
27-
client.connect(err => {
28-
expect(err).to.not.exist;
24+
it(
25+
'should respect writeConcern from uri',
26+
withMonitoredClient('insert', { queryOptions: { w: 0 } }, function(client, events, done) {
2927
expect(client.writeConcern).to.eql({ w: 0 });
30-
client.close(done);
31-
});
32-
});
28+
client
29+
.db('test')
30+
.collection('test')
31+
.insertOne({ a: 1 }, (err, result) => {
32+
expect(err).to.not.exist;
33+
expect(result).to.exist;
34+
expect(events)
35+
.to.be.an('array')
36+
.with.lengthOf(1);
37+
expect(events[0]).to.containSubset({
38+
commandName: 'insert',
39+
command: {
40+
writeConcern: { w: 0 }
41+
}
42+
});
43+
done();
44+
});
45+
})
46+
);
3347

3448
// TODO: once `read-write-concern/connection-string` spec tests are implemented these can likely be removed
3549
describe('test journal connection string option', function() {

0 commit comments

Comments
 (0)