Skip to content

Commit

Permalink
fix(NODE-3521): remove extra server selection
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Feb 25, 2022
1 parent a0dfc5b commit c33eb3a
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 93 deletions.
8 changes: 0 additions & 8 deletions src/operations/execute_operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ export function executeOperation<
}

return maybePromise(callback, cb => {
if (topology.shouldCheckForSessionSupport()) {
return topology.selectServer(ReadPreference.primaryPreferred, err => {
if (err) return cb(err);

executeOperation<T, TResult>(topology, operation, cb);
});
}

// The driver sessions spec mandates that we implicitly create sessions for operations
// that are not explicitly provided with a session.
let session: ClientSession | undefined = operation.session;
Expand Down
11 changes: 0 additions & 11 deletions src/sdam/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,17 +630,6 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {

// Sessions related methods

/**
* @returns Whether the topology should initiate selection to determine session support
*/
shouldCheckForSessionSupport(): boolean {
if (this.description.type === TopologyType.Single) {
return !this.description.hasKnownServers;
}

return !this.description.hasDataBearingServers;
}

/** Start a logical session */
startSession(options: ClientSessionOptions, clientOptions?: MongoOptions): ClientSession {
const session = new ClientSession(this, this.s.sessionPool, options, clientOptions);
Expand Down
74 changes: 0 additions & 74 deletions test/unit/sdam/topology.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,80 +77,6 @@ describe('Topology (unit)', function () {
});
});

describe('shouldCheckForSessionSupport', function () {
beforeEach(function () {
this.sinon = sinon.createSandbox();

// these are mocks we want across all tests
this.sinon.stub(Server.prototype, 'requestCheck');
this.sinon
.stub(Topology.prototype, 'selectServer')
.callsFake(function (selector, options, callback) {
setTimeout(() => {
const server = Array.from(this.s.servers.values())[0];
callback(null, server);
}, 50);
});
});

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.s.state = 'connected';
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.s.state = 'connected';
this.emit('connect');

setTimeout(() => {
this.emit(
'descriptionReceived',
new ServerDescription('someserver:27019', { ok: 1, maxWireVersion: 6 })
);
}, 20);
});

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.s.state = 'connected';
this.emit('connect');

setTimeout(() => {
this.emit(
'descriptionReceived',
new ServerDescription(this.name, { ok: 1, msg: 'isdbgrid', maxWireVersion: 6 })
);
}, 20);
});

topology.connect(() => {
expect(topology.shouldCheckForSessionSupport()).to.be.false;
topology.close(done);
});
});
});

describe('black holes', function () {
let mockServer;
beforeEach(() => mock.createServer().then(server => (mockServer = server)));
Expand Down

0 comments on commit c33eb3a

Please sign in to comment.