Skip to content
Merged
Changes from all commits
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
93 changes: 53 additions & 40 deletions test/integration/client-side-operations-timeout/node_csot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1359,49 +1359,62 @@ describe('CSOT driver tests', metadata, () => {
});
});

describe('Connection after timeout', { requires: { mongodb: '>=4.4' } }, function () {
let client: MongoClient;

beforeEach(async function () {
client = this.configuration.newClient({ timeoutMS: 500 });

const failpoint: FailPoint = {
configureFailPoint: 'failCommand',
mode: {
times: 1
},
data: {
failCommands: ['insert'],
blockConnection: true,
blockTimeMS: 700
}
};

await client.db('admin').command(failpoint);
});
// TODO(NODE-7118): Find a way to reimplement this test for latest server.
describe(
'Connection after timeout',
{
requires: {
// 4.4 for use of failCommands
// < 8.3 because of https://jira.mongodb.org/browse/SERVER-101116
mongodb: '>=4.4 <=8.2'
}
},
function () {
let client: MongoClient;

afterEach(async function () {
await client.close();
});
beforeEach(async function () {
client = this.configuration.newClient({ timeoutMS: 500 });

it('closes so pending messages are not read by another operation', async function () {
const cmap = [];
client.on('connectionCheckedOut', ev => cmap.push(ev));
client.on('connectionClosed', ev => cmap.push(ev));
const failpoint: FailPoint = {
configureFailPoint: 'failCommand',
mode: {
times: 1
},
data: {
failCommands: ['insert'],
blockConnection: true,
blockTimeMS: 700
}
};

const error = await client
.db('socket')
.collection('closes')
.insertOne({})
.catch(error => error);
await client.db('admin').command(failpoint);
});

expect(error).to.be.instanceOf(MongoOperationTimeoutError);
expect(cmap).to.have.lengthOf(2);
afterEach(async function () {
await client.close();
});

const [checkedOut, closed] = cmap;
expect(checkedOut).to.have.property('name', 'connectionCheckedOut');
expect(closed).to.have.property('name', 'connectionClosed');
expect(checkedOut).to.have.property('connectionId', closed.connectionId);
});
});
it('closes so pending messages are not read by another operation', async function () {
const cmap = [];
client.on('connectionCheckedOut', ev => cmap.push(ev));
client.on('connectionClosed', ev => cmap.push(ev));

const error = await client
.db('socket')
.collection('closes')
.insertOne({})
.catch(error => error);

// Note: In the case where the timeout comes from the server, the driver does not
// need to close the connection as no more potential messages are expected.
expect(error).to.be.instanceOf(MongoOperationTimeoutError);
expect(cmap).to.have.lengthOf(2);

const [checkedOut, closed] = cmap;
expect(checkedOut).to.have.property('name', 'connectionCheckedOut');
expect(closed).to.have.property('name', 'connectionClosed');
expect(checkedOut).to.have.property('connectionId', closed.connectionId);
});
}
);
});