Skip to content

fix(NODE-4854): set timeout on write and reset on message #3582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Mar 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: connection creation does not set socketTimeoutMS
  • Loading branch information
nbbeeken committed Feb 28, 2023
commit 76cab39ca6fbc9a8389ba8ca31ea3e41e65e6369
49 changes: 43 additions & 6 deletions test/unit/cmap/connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ import {
import { genClusterTime } from '../../tools/common';
import * as mock from '../../tools/mongodb-mock/index';

const CONNECT_DEFAULTS = {
id: 1,
tls: false,
generation: 1,
monitorCommands: false,
metadata: {} as ClientMetadata,
loadBalanced: false
};

describe('Connect Tests', function () {
context('when PLAIN auth enabled', () => {
const test: {
Expand All @@ -29,12 +38,7 @@ describe('Connect Tests', function () {
const mockServer = await mock.createServer();
test.server = mockServer;
test.connectOptions = {
id: 1,
tls: false,
generation: 1,
monitorCommands: false,
metadata: {} as ClientMetadata,
loadBalanced: false,
...CONNECT_DEFAULTS,
hostAddress: test.server.hostAddress() as HostAddress,
credentials: new MongoCredentials({
username: 'testUser',
Expand Down Expand Up @@ -112,6 +116,39 @@ describe('Connect Tests', function () {
});
});

context('when creating a connection', () => {
let server;
let connectOptions;
let connection: Connection;

beforeEach(async () => {
server = await mock.createServer();
server.setMessageHandler(request => {
if (isHello(request.document)) {
request.reply(mock.HELLO);
}
});
connectOptions = {
...CONNECT_DEFAULTS,
hostAddress: server.hostAddress() as HostAddress
};

connection = await promisify<Connection>(callback =>
//@ts-expect-error: Callbacks do not have mutual exclusion for error/result existence
connect(connectOptions, callback)
)();
});

afterEach(async () => {
connection.destroy({ force: true });
await mock.cleanup();
});

it('creates a connection with an infinite timeout', async () => {
expect(connection.stream).to.have.property('timeout', 0);
});
});

it('should emit `MongoNetworkError` for network errors', function (done) {
connect({ hostAddress: new HostAddress('non-existent:27018') }, err => {
expect(err).to.be.instanceOf(MongoNetworkError);
Expand Down