This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(error): add more specific error type for write concern errors
Presently we wrap all reported `writeConcernError`s with a simple `MongoError`, which makes it difficult to specialize on this case in situations such as retry logic. NODE-1516
- Loading branch information
Showing
4 changed files
with
88 additions
and
18 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
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,50 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const mock = require('mongodb-mock-server'); | ||
const Server = require('../../../lib/topologies/server'); | ||
const MongoWriteConcernError = require('../../../lib/error').MongoWriteConcernError; | ||
|
||
const test = {}; | ||
describe('Pool (unit)', function() { | ||
afterEach(() => mock.cleanup()); | ||
beforeEach(() => { | ||
return mock.createServer().then(mockServer => { | ||
test.server = mockServer; | ||
}); | ||
}); | ||
|
||
it('should throw a MongoWriteConcernError when a writeConcernError is present', function(done) { | ||
test.server.setMessageHandler(request => { | ||
const doc = request.document; | ||
if (doc.ismaster) { | ||
return request.reply(Object.assign({}, mock.DEFAULT_ISMASTER)); | ||
} else if (doc.insert) { | ||
return request.reply({ | ||
ok: 1, | ||
writeConcernError: { | ||
code: 64, | ||
codeName: 'WriteConcernFailed', | ||
errmsg: 'waiting for replication timed out', | ||
errInfo: { | ||
wtimeout: true | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
const client = new Server(test.server.address()); | ||
client.on('error', done); | ||
client.once('connect', () => { | ||
client.insert('fake.ns', { a: 1 }, (err, result) => { | ||
expect(err).to.exist; | ||
expect(result).to.not.exist; | ||
expect(err).to.be.instanceOf(MongoWriteConcernError); | ||
done(); | ||
}); | ||
}); | ||
|
||
client.connect(); | ||
}); | ||
}); |