Skip to content

Commit e9196ab

Browse files
authored
refactor(NODE-3324): bump max wire version to 13 (#2875)
1 parent 3ce148d commit e9196ab

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

lib/core/wireprotocol/constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

33
const MIN_SUPPORTED_SERVER_VERSION = '2.6';
4-
const MAX_SUPPORTED_SERVER_VERSION = '4.4';
4+
const MAX_SUPPORTED_SERVER_VERSION = '5.0';
55
const MIN_SUPPORTED_WIRE_VERSION = 2;
6-
const MAX_SUPPORTED_WIRE_VERSION = 9;
6+
const MAX_SUPPORTED_WIRE_VERSION = 13;
77

88
module.exports = {
99
MIN_SUPPORTED_SERVER_VERSION,

test/unit/wire_version.test.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
'use strict';
2+
3+
const mock = require('mongodb-mock-server');
4+
const expect = require('chai').expect;
5+
const MongoServerSelectionError = require('../../lib/core/error').MongoServerSelectionError;
6+
7+
const minCompatErrMsg = `minimum wire version ${Number.MAX_SAFE_INTEGER -
8+
1}, but this version of the Node.js Driver requires at most 13`;
9+
const maxCompatErrMsg = `reports maximum wire version 1, but this version of the Node.js Driver requires at least 2`;
10+
11+
describe('Wire Protocol Version', () => {
12+
let server;
13+
14+
function setWireProtocolMessageHandler(min, max) {
15+
server.setMessageHandler(req => {
16+
const doc = req.document;
17+
if (doc.ismaster || doc.hello) {
18+
const hello = Object.assign({}, mock.DEFAULT_ISMASTER_36, {
19+
minWireVersion: min,
20+
maxWireVersion: max
21+
});
22+
return req.reply(hello);
23+
}
24+
});
25+
}
26+
27+
beforeEach(() => {
28+
return mock.createServer().then(s => {
29+
server = s;
30+
});
31+
});
32+
afterEach(() => {
33+
return mock.cleanup();
34+
});
35+
36+
describe('minimum is greater than 13', () => {
37+
it('should raise a compatibility error', function() {
38+
setWireProtocolMessageHandler(Number.MAX_SAFE_INTEGER - 1, Number.MAX_SAFE_INTEGER);
39+
40+
const client = this.configuration.newClient(
41+
`mongodb://${server.uri()}/wireVersionTest?serverSelectionTimeoutMS=200`
42+
);
43+
return client
44+
.connect()
45+
.then(() => {
46+
expect.fail('should fail to select server!');
47+
})
48+
.catch(error => {
49+
expect(error).to.be.instanceOf(MongoServerSelectionError);
50+
expect(error)
51+
.to.have.property('message')
52+
.that.includes(minCompatErrMsg);
53+
});
54+
});
55+
});
56+
57+
describe('maximum is less than 2', () => {
58+
it('should raise a compatibility error', function() {
59+
setWireProtocolMessageHandler(1, 1);
60+
61+
const client = this.configuration.newClient(
62+
`mongodb://${server.uri()}/wireVersionTest?serverSelectionTimeoutMS=200`
63+
);
64+
return client
65+
.connect()
66+
.then(() => {
67+
expect.fail('should fail to select server!');
68+
})
69+
.catch(error => {
70+
expect(error).to.be.instanceOf(MongoServerSelectionError);
71+
expect(error)
72+
.to.have.property('message')
73+
.that.includes(maxCompatErrMsg);
74+
});
75+
});
76+
});
77+
});

0 commit comments

Comments
 (0)