Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/sdam/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ function checkServer(monitor: Monitor, callback: Callback<Document>) {
: { ismaster: true };

const options = isAwaitable
? { socketTimeout: connectTimeoutMS + maxAwaitTimeMS, exhaustAllowed: true }
? {
socketTimeout: connectTimeoutMS ? connectTimeoutMS + maxAwaitTimeMS : 0,
exhaustAllowed: true
}
: { socketTimeout: connectTimeoutMS };

if (isAwaitable && monitor[kRTTPinger] == null) {
Expand Down
61 changes: 57 additions & 4 deletions test/functional/mongo_client_options.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
const test = require('./shared').assert,
setupDatabase = require('./shared').setupDatabase,
expect = require('chai').expect;
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 () {
Expand All @@ -22,11 +23,63 @@ describe('MongoClient Options', function () {
validateOptions: true
},
function (err, client) {
test.ok(err.message.indexOf('option notlegal is not supported') !== -1);
expect(err)
.property('message')
.to.match(/option notlegal is not supported/);
expect(client).to.not.exist;
done();
}
);
}
});

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 === 'admin.$cmd' && command.ismaster && options.exhaustAllowed) {
stub.restore();
expect(options).property('socketTimeout').to.equal(0);
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 === 'admin.$cmd' && command.ismaster && options.exhaustAllowed) {
stub.restore();
expect(options).property('socketTimeout').to.equal(510);
client.close(done);
}
stub.wrappedMethod.apply(this, args);
});
});
}
});
});