/
mongo_client_options.test.js
111 lines (104 loc) · 3.37 KB
/
mongo_client_options.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
'use strict';
const sinon = require('sinon');
const { setupDatabase } = require('./shared');
const { expect } = require('chai');
const { MongoClient } = require('../../src');
const { Connection } = require('../../src/cmap/connection');
describe('MongoClient Options', function () {
before(function () {
return setupDatabase(this.configuration);
});
it('should error on unexpected options', {
metadata: { requires: { topology: 'single' } },
test: function (done) {
var configuration = this.configuration;
MongoClient.connect(
configuration.url(),
{
maxPoolSize: 4,
notlegal: {},
validateOptions: true
},
function (err, client) {
expect(err)
.property('message')
.to.match(/options notlegal, validateoptions are not supported/);
expect(client).to.not.exist;
done();
}
);
}
});
it('should error on unexpected options (promise)', {
metadata: { requires: { topology: 'single' } },
test() {
MongoClient.connect(this.configuration.url(), {
maxPoolSize: 4,
notlegal: {},
validateOptions: true
})
.then(() => expect().fail())
.catch(err => {
expect(err)
.property('message')
.to.match(/options notlegal, validateoptions are not supported/);
});
}
});
it('must respect an infinite connectTimeoutMS for the streaming protocol', {
metadata: { requires: { topology: 'replicaset', mongodb: '>= 4.4' } },
test: function (done) {
const client = this.configuration.newClient({
connectTimeoutMS: 0,
heartbeatFrequencyMS: 500
});
client.connect(err => {
expect(err).to.not.exist;
const stub = sinon.stub(Connection.prototype, 'command').callsFake(function () {
const args = Array.prototype.slice.call(arguments);
const ns = args[0];
const command = args[1];
const options = args[2] || {};
if (
ns.toString() === 'admin.$cmd' &&
(command.ismaster || command.hello) &&
options.exhaustAllowed
) {
expect(options).property('socketTimeoutMS').to.equal(0);
stub.restore();
client.close(done);
}
stub.wrappedMethod.apply(this, args);
});
});
}
});
it('must respect a finite connectTimeoutMS for the streaming protocol', {
metadata: { requires: { topology: 'replicaset', mongodb: '>= 4.4' } },
test: function (done) {
const client = this.configuration.newClient({
connectTimeoutMS: 10,
heartbeatFrequencyMS: 500
});
client.connect(err => {
expect(err).to.not.exist;
const stub = sinon.stub(Connection.prototype, 'command').callsFake(function () {
const args = Array.prototype.slice.call(arguments);
const ns = args[0];
const command = args[1];
const options = args[2] || {};
if (
ns.toString() === 'admin.$cmd' &&
(command.ismaster || command.hello) &&
options.exhaustAllowed
) {
expect(options).property('socketTimeoutMS').to.equal(510);
stub.restore();
client.close(done);
}
stub.wrappedMethod.apply(this, args);
});
});
}
});
});