Skip to content

Commit 564449c

Browse files
committed
chore: add nodelay
1 parent 4c0e2fb commit 564449c

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

src/cmap/connect.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ function parseConnectOptions(options: ConnectionOptions): SocketConnectOpts {
311311
result.keepAliveInitialDelay = 120000;
312312
}
313313
result.keepAlive = true;
314+
result.noDelay = options.noDelay ?? true;
314315

315316
if (typeof hostAddress.socketPath === 'string') {
316317
result.path = hostAddress.socketPath;
@@ -352,7 +353,6 @@ function parseSslOptions(options: MakeConnectionOptions): TLSConnectionOpts {
352353

353354
export async function makeSocket(options: MakeConnectionOptions): Promise<Stream> {
354355
const useTLS = options.tls ?? false;
355-
const noDelay = options.noDelay ?? true;
356356
const connectTimeoutMS = options.connectTimeoutMS ?? 30000;
357357
const existingSocket = options.existingSocket;
358358

@@ -382,7 +382,6 @@ export async function makeSocket(options: MakeConnectionOptions): Promise<Stream
382382
}
383383

384384
socket.setTimeout(connectTimeoutMS);
385-
socket.setNoDelay(noDelay);
386385

387386
let cancellationHandler: ((err: Error) => void) | null = null;
388387

test/integration/node-specific/mongo_client.test.ts

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,56 @@ describe('class MongoClient', function () {
243243
);
244244
});
245245
});
246+
247+
context('when noDelay is not provided', function () {
248+
let client;
249+
let spy;
250+
251+
beforeEach(async function () {
252+
spy = sinon.spy(net, 'createConnection');
253+
client = this.configuration.newClient();
254+
await client.connect();
255+
});
256+
257+
afterEach(async function () {
258+
await client?.close();
259+
spy.restore();
260+
});
261+
262+
it('sets noDelay to true', function () {
263+
expect(spy).to.have.been.calledWith(
264+
sinon.match({
265+
noDelay: true
266+
})
267+
);
268+
});
269+
});
270+
271+
context('when noDelay is provided', function () {
272+
let client;
273+
let spy;
274+
275+
beforeEach(async function () {
276+
const options = { noDelay: false };
277+
spy = sinon.spy(net, 'createConnection');
278+
const uri = this.configuration.url();
279+
client = new MongoClient(uri, options);
280+
await client.connect();
281+
});
282+
283+
afterEach(async function () {
284+
await client?.close();
285+
spy.restore();
286+
});
287+
288+
it('sets noDelay', function () {
289+
expect(spy).to.have.been.calledWith(
290+
sinon.match({
291+
noDelay: false
292+
})
293+
);
294+
});
295+
});
246296
});
247297

248298
it('Should correctly pass through appname', {
@@ -999,12 +1049,12 @@ describe('class MongoClient', function () {
9991049
metadata: { requires: { topology: ['single'] } },
10001050
test: async function () {
10011051
await client.connect();
1002-
expect(netSpy).to.have.been.calledWith({
1003-
autoSelectFamily: false,
1004-
autoSelectFamilyAttemptTimeout: 100,
1005-
host: 'localhost',
1006-
port: 27017
1007-
});
1052+
expect(netSpy).to.have.been.calledWith(
1053+
sinon.match({
1054+
autoSelectFamily: false,
1055+
autoSelectFamilyAttemptTimeout: 100
1056+
})
1057+
);
10081058
}
10091059
});
10101060
});
@@ -1018,11 +1068,11 @@ describe('class MongoClient', function () {
10181068
metadata: { requires: { topology: ['single'] } },
10191069
test: async function () {
10201070
await client.connect();
1021-
expect(netSpy).to.have.been.calledWith({
1022-
autoSelectFamily: true,
1023-
host: 'localhost',
1024-
port: 27017
1025-
});
1071+
expect(netSpy).to.have.been.calledWith(
1072+
sinon.match({
1073+
autoSelectFamily: true
1074+
})
1075+
);
10261076
}
10271077
});
10281078
});

0 commit comments

Comments
 (0)