-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(topology): correct logic for checking for sessions support
The logic for checking for sessions support was flawed, in that if it was connect to a single server it would check the conditions for single server session support and, failing that, would back off to the generalized support check. These cases have been split up, and unit tests were added. Additionally, a typeo was fixed when determining if a topology had known servers. NODE-2342
- Loading branch information
Showing
3 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
const Topology = require('../../../lib/core/sdam/topology').Topology; | ||
const Server = require('../../../lib/core/sdam/server').Server; | ||
const ServerDescription = require('../../../lib/core/sdam/server_description').ServerDescription; | ||
const expect = require('chai').expect; | ||
const sinon = require('sinon'); | ||
|
||
describe('Topology (unit)', function() { | ||
describe('shouldCheckForSessionSupport', function() { | ||
beforeEach(function() { | ||
this.sinon = sinon.sandbox.create(); | ||
|
||
// these are mocks we want across all tests | ||
this.sinon.stub(Server.prototype, 'monitor'); | ||
this.sinon | ||
.stub(Topology.prototype, 'selectServer') | ||
.callsFake(function(selector, options, callback) { | ||
const server = Array.from(this.s.servers.values())[0]; | ||
callback(null, server); | ||
}); | ||
}); | ||
|
||
afterEach(function() { | ||
this.sinon.restore(); | ||
}); | ||
|
||
it('should check for sessions if connected to a single server and has no known servers', function(done) { | ||
const topology = new Topology('someserver:27019'); | ||
this.sinon.stub(Server.prototype, 'connect').callsFake(function() { | ||
this.emit('connect'); | ||
}); | ||
|
||
topology.connect(() => { | ||
expect(topology.shouldCheckForSessionSupport()).to.be.true; | ||
topology.close(done); | ||
}); | ||
}); | ||
|
||
it('should not check for sessions if connected to a single server', function(done) { | ||
const topology = new Topology('someserver:27019'); | ||
this.sinon.stub(Server.prototype, 'connect').callsFake(function() { | ||
this.emit( | ||
'descriptionReceived', | ||
new ServerDescription('someserver:27019', { ok: 1, maxWireVersion: 5 }) | ||
); | ||
|
||
this.emit('connect'); | ||
}); | ||
|
||
topology.connect(() => { | ||
expect(topology.shouldCheckForSessionSupport()).to.be.false; | ||
topology.close(done); | ||
}); | ||
}); | ||
|
||
it('should check for sessions if there are no data-bearing nodes', function(done) { | ||
const topology = new Topology('mongos:27019,mongos:27018,mongos:27017'); | ||
this.sinon.stub(Server.prototype, 'connect').callsFake(function() { | ||
this.emit( | ||
'descriptionReceived', | ||
new ServerDescription(this.name, { ok: 1, msg: 'isdbgrid', maxWireVersion: 5 }) | ||
); | ||
|
||
this.emit('connect'); | ||
}); | ||
|
||
topology.connect(() => { | ||
expect(topology.shouldCheckForSessionSupport()).to.be.false; | ||
topology.close(done); | ||
}); | ||
}); | ||
}); | ||
}); |