Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
fix(mongos-replset): pass connect options to child server instances
Browse files Browse the repository at this point in the history
This allows for options determined during uri parsing to make it
down to the creation of child Server instances using the legacy
SDAM topology classes.

NODE-1798
  • Loading branch information
mbroadst committed Dec 14, 2018
1 parent f93309a commit 7ffb4bb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/topologies/mongos.js
Expand Up @@ -286,7 +286,7 @@ Mongos.prototype.connect = function(options) {
// Create server instances
var servers = this.s.seedlist.map(function(x) {
const server = new Server(
Object.assign({}, self.s.options, x, {
Object.assign({}, self.s.options, x, options, {
authProviders: self.authProviders,
reconnect: false,
monitoring: false,
Expand Down
4 changes: 3 additions & 1 deletion lib/topologies/replset.js
Expand Up @@ -960,12 +960,14 @@ ReplSet.prototype.connect = function(options) {
var self = this;
// Add any connect level options to the internal state
this.s.connectOptions = options || {};

// Set connecting state
stateTransition(this, CONNECTING);

// Create server instances
var servers = this.s.seedlist.map(function(x) {
return new Server(
Object.assign({}, self.s.options, x, {
Object.assign({}, self.s.options, x, options, {
authProviders: self.authProviders,
reconnect: false,
monitoring: false,
Expand Down
53 changes: 53 additions & 0 deletions test/tests/unit/replset/compression_tests.js
@@ -0,0 +1,53 @@
'use strict';

const ReplSet = require('../../../../lib/topologies/replset');
const mock = require('mongodb-mock-server');
const ReplSetFixture = require('../common').ReplSetFixture;
const expect = require('chai').expect;

describe('Compression (ReplSet)', function() {
let test;
before(() => (test = new ReplSetFixture()));
afterEach(() => mock.cleanup());
beforeEach(() => test.setup());

it('should pass compression information to child server instances on connect', function(done) {
const compressionData = [];
test.primaryServer.setMessageHandler(request => {
const doc = request.document;
if (doc.ismaster) {
compressionData.push(doc.compression);
request.reply(test.primaryStates[0]);
}
});

test.firstSecondaryServer.setMessageHandler(request => {
const doc = request.document;
if (doc.ismaster) {
compressionData.push(doc.compression);
request.reply(test.firstSecondaryStates[0]);
}
});

const replSet = new ReplSet(
[test.primaryServer.address(), test.firstSecondaryServer.address()],
{
setName: 'rs',
haInterval: 10000,
connectionTimeout: 3000,
secondaryOnlyConnectionAllowed: true,
size: 1
}
);

replSet.on('fullsetup', () => {
compressionData.forEach(data => {
expect(data).to.eql(['zlib']);
});

done();
});

replSet.connect({ compression: { compressors: ['zlib'] } });
});
});

0 comments on commit 7ffb4bb

Please sign in to comment.