Skip to content

Commit c33eb3a

Browse files
committed
fix(NODE-3521): remove extra server selection
1 parent a0dfc5b commit c33eb3a

File tree

3 files changed

+0
-93
lines changed

3 files changed

+0
-93
lines changed

src/operations/execute_operation.ts

-8
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ export function executeOperation<
7777
}
7878

7979
return maybePromise(callback, cb => {
80-
if (topology.shouldCheckForSessionSupport()) {
81-
return topology.selectServer(ReadPreference.primaryPreferred, err => {
82-
if (err) return cb(err);
83-
84-
executeOperation<T, TResult>(topology, operation, cb);
85-
});
86-
}
87-
8880
// The driver sessions spec mandates that we implicitly create sessions for operations
8981
// that are not explicitly provided with a session.
9082
let session: ClientSession | undefined = operation.session;

src/sdam/topology.ts

-11
Original file line numberDiff line numberDiff line change
@@ -630,17 +630,6 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
630630

631631
// Sessions related methods
632632

633-
/**
634-
* @returns Whether the topology should initiate selection to determine session support
635-
*/
636-
shouldCheckForSessionSupport(): boolean {
637-
if (this.description.type === TopologyType.Single) {
638-
return !this.description.hasKnownServers;
639-
}
640-
641-
return !this.description.hasDataBearingServers;
642-
}
643-
644633
/** Start a logical session */
645634
startSession(options: ClientSessionOptions, clientOptions?: MongoOptions): ClientSession {
646635
const session = new ClientSession(this, this.s.sessionPool, options, clientOptions);

test/unit/sdam/topology.test.js

-74
Original file line numberDiff line numberDiff line change
@@ -77,80 +77,6 @@ describe('Topology (unit)', function () {
7777
});
7878
});
7979

80-
describe('shouldCheckForSessionSupport', function () {
81-
beforeEach(function () {
82-
this.sinon = sinon.createSandbox();
83-
84-
// these are mocks we want across all tests
85-
this.sinon.stub(Server.prototype, 'requestCheck');
86-
this.sinon
87-
.stub(Topology.prototype, 'selectServer')
88-
.callsFake(function (selector, options, callback) {
89-
setTimeout(() => {
90-
const server = Array.from(this.s.servers.values())[0];
91-
callback(null, server);
92-
}, 50);
93-
});
94-
});
95-
96-
afterEach(function () {
97-
this.sinon.restore();
98-
});
99-
100-
it('should check for sessions if connected to a single server and has no known servers', function (done) {
101-
const topology = new Topology('someserver:27019');
102-
this.sinon.stub(Server.prototype, 'connect').callsFake(function () {
103-
this.s.state = 'connected';
104-
this.emit('connect');
105-
});
106-
107-
topology.connect(() => {
108-
expect(topology.shouldCheckForSessionSupport()).to.be.true;
109-
topology.close(done);
110-
});
111-
});
112-
113-
it('should not check for sessions if connected to a single server', function (done) {
114-
const topology = new Topology('someserver:27019');
115-
this.sinon.stub(Server.prototype, 'connect').callsFake(function () {
116-
this.s.state = 'connected';
117-
this.emit('connect');
118-
119-
setTimeout(() => {
120-
this.emit(
121-
'descriptionReceived',
122-
new ServerDescription('someserver:27019', { ok: 1, maxWireVersion: 6 })
123-
);
124-
}, 20);
125-
});
126-
127-
topology.connect(() => {
128-
expect(topology.shouldCheckForSessionSupport()).to.be.false;
129-
topology.close(done);
130-
});
131-
});
132-
133-
it('should check for sessions if there are no data-bearing nodes', function (done) {
134-
const topology = new Topology(['mongos:27019', 'mongos:27018', 'mongos:27017'], {});
135-
this.sinon.stub(Server.prototype, 'connect').callsFake(function () {
136-
this.s.state = 'connected';
137-
this.emit('connect');
138-
139-
setTimeout(() => {
140-
this.emit(
141-
'descriptionReceived',
142-
new ServerDescription(this.name, { ok: 1, msg: 'isdbgrid', maxWireVersion: 6 })
143-
);
144-
}, 20);
145-
});
146-
147-
topology.connect(() => {
148-
expect(topology.shouldCheckForSessionSupport()).to.be.false;
149-
topology.close(done);
150-
});
151-
});
152-
});
153-
15480
describe('black holes', function () {
15581
let mockServer;
15682
beforeEach(() => mock.createServer().then(server => (mockServer = server)));

0 commit comments

Comments
 (0)