Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: honor journal=true in connection string (#2359)
Ensure the journal option returned by parseQueryString is converted into j during the connect operation. This fixes the issue of the write concern not being set on commands where journal is only specified in the connection string. NODE-2422
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
chai.use(require('chai-subset')); | ||
const withMonitoredClient = require('./shared').withMonitoredClient; | ||
|
||
describe('Write Concern', function() { | ||
describe('test journal connection string option', function() { | ||
function journalOptionTest(client, events, done) { | ||
expect(client).to.have.nested.property('s.options'); | ||
const clientOptions = client.s.options; | ||
expect(clientOptions).property('j').to.be.true; | ||
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: { j: true } | ||
} | ||
}); | ||
done(); | ||
}); | ||
} | ||
|
||
// baseline to confirm client option is working | ||
it( | ||
'should set write concern with j: true client option', | ||
withMonitoredClient('insert', { clientOptions: { j: true } }, journalOptionTest) | ||
); | ||
|
||
// ensure query option in connection string passes through | ||
it( | ||
'should set write concern with journal=true connection string option', | ||
withMonitoredClient('insert', { queryOptions: { journal: true } }, journalOptionTest) | ||
); | ||
}); | ||
}); |