|
2 | 2 | const test = require('./shared').assert;
|
3 | 3 | const setupDatabase = require('./shared').setupDatabase;
|
4 | 4 | const expect = require('chai').expect;
|
| 5 | +const sinon = require('sinon'); |
| 6 | +const Connection = require('../../lib/cmap/connection').Connection; |
5 | 7 |
|
6 | 8 | describe('MongoClient Options', function() {
|
7 | 9 | before(function() {
|
@@ -110,6 +112,62 @@ describe('MongoClient Options', function() {
|
110 | 112 | });
|
111 | 113 | });
|
112 | 114 |
|
| 115 | + it('must respect an infinite connectTimeoutMS for the streaming protocol', { |
| 116 | + metadata: { requires: { topology: 'replicaset', mongodb: '>= 4.4' } }, |
| 117 | + test: function(done) { |
| 118 | + if (!this.configuration.usingUnifiedTopology()) return done(); |
| 119 | + const client = this.configuration.newClient({ |
| 120 | + connectTimeoutMS: 0, |
| 121 | + heartbeatFrequencyMS: 500 |
| 122 | + }); |
| 123 | + client.connect(err => { |
| 124 | + expect(err).to.not.exist; |
| 125 | + const stub = sinon.stub(Connection.prototype, 'command').callsFake(function() { |
| 126 | + const args = Array.prototype.slice.call(arguments); |
| 127 | + const ns = args[0]; |
| 128 | + const command = args[1]; |
| 129 | + const options = args[2]; |
| 130 | + if (ns === 'admin.$cmd' && command.ismaster && options.exhaustAllowed) { |
| 131 | + stub.restore(); |
| 132 | + expect(options) |
| 133 | + .property('socketTimeout') |
| 134 | + .to.equal(0); |
| 135 | + client.close(done); |
| 136 | + } |
| 137 | + stub.wrappedMethod.apply(this, args); |
| 138 | + }); |
| 139 | + }); |
| 140 | + } |
| 141 | + }); |
| 142 | + |
| 143 | + it('must respect a finite connectTimeoutMS for the streaming protocol', { |
| 144 | + metadata: { requires: { topology: 'replicaset', mongodb: '>= 4.4' } }, |
| 145 | + test: function(done) { |
| 146 | + if (!this.configuration.usingUnifiedTopology()) return done(); |
| 147 | + const client = this.configuration.newClient({ |
| 148 | + connectTimeoutMS: 10, |
| 149 | + heartbeatFrequencyMS: 500 |
| 150 | + }); |
| 151 | + client.connect(err => { |
| 152 | + expect(err).to.not.exist; |
| 153 | + const stub = sinon.stub(Connection.prototype, 'command').callsFake(function() { |
| 154 | + const args = Array.prototype.slice.call(arguments); |
| 155 | + const ns = args[0]; |
| 156 | + const command = args[1]; |
| 157 | + const options = args[2]; |
| 158 | + if (ns === 'admin.$cmd' && command.ismaster && options.exhaustAllowed) { |
| 159 | + stub.restore(); |
| 160 | + expect(options) |
| 161 | + .property('socketTimeout') |
| 162 | + .to.equal(510); |
| 163 | + client.close(done); |
| 164 | + } |
| 165 | + stub.wrappedMethod.apply(this, args); |
| 166 | + }); |
| 167 | + }); |
| 168 | + } |
| 169 | + }); |
| 170 | + |
113 | 171 | /**
|
114 | 172 | * @ignore
|
115 | 173 | */
|
|
0 commit comments