-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
79 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
|
||
const mock = require('mongodb-mock-server'); | ||
const expect = require('chai').expect; | ||
const MongoServerSelectionError = require('../../lib/core/error').MongoServerSelectionError; | ||
|
||
const minCompatErrMsg = `minimum wire version ${Number.MAX_SAFE_INTEGER - | ||
1}, but this version of the Node.js Driver requires at most 13`; | ||
const maxCompatErrMsg = `reports maximum wire version 1, but this version of the Node.js Driver requires at least 2`; | ||
|
||
describe('Wire Protocol Version', () => { | ||
let server; | ||
|
||
function setWireProtocolMessageHandler(min, max) { | ||
server.setMessageHandler(req => { | ||
const doc = req.document; | ||
if (doc.ismaster || doc.hello) { | ||
const hello = Object.assign({}, mock.DEFAULT_ISMASTER_36, { | ||
minWireVersion: min, | ||
maxWireVersion: max | ||
}); | ||
return req.reply(hello); | ||
} | ||
}); | ||
} | ||
|
||
beforeEach(() => { | ||
return mock.createServer().then(s => { | ||
server = s; | ||
}); | ||
}); | ||
afterEach(() => { | ||
return mock.cleanup(); | ||
}); | ||
|
||
describe('minimum is greater than 13', () => { | ||
it('should raise a compatibility error', function() { | ||
setWireProtocolMessageHandler(Number.MAX_SAFE_INTEGER - 1, Number.MAX_SAFE_INTEGER); | ||
|
||
const client = this.configuration.newClient( | ||
`mongodb://${server.uri()}/wireVersionTest?serverSelectionTimeoutMS=200` | ||
); | ||
return client | ||
.connect() | ||
.then(() => { | ||
expect.fail('should fail to select server!'); | ||
}) | ||
.catch(error => { | ||
expect(error).to.be.instanceOf(MongoServerSelectionError); | ||
expect(error) | ||
.to.have.property('message') | ||
.that.includes(minCompatErrMsg); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('maximum is less than 2', () => { | ||
it('should raise a compatibility error', function() { | ||
setWireProtocolMessageHandler(1, 1); | ||
|
||
const client = this.configuration.newClient( | ||
`mongodb://${server.uri()}/wireVersionTest?serverSelectionTimeoutMS=200` | ||
); | ||
return client | ||
.connect() | ||
.then(() => { | ||
expect.fail('should fail to select server!'); | ||
}) | ||
.catch(error => { | ||
expect(error).to.be.instanceOf(MongoServerSelectionError); | ||
expect(error) | ||
.to.have.property('message') | ||
.that.includes(maxCompatErrMsg); | ||
}); | ||
}); | ||
}); | ||
}); |