diff --git a/test/integration/client-side-operations-timeout/node_csot.test.ts b/test/integration/client-side-operations-timeout/node_csot.test.ts index 8b056989de..2412e4f785 100644 --- a/test/integration/client-side-operations-timeout/node_csot.test.ts +++ b/test/integration/client-side-operations-timeout/node_csot.test.ts @@ -105,43 +105,62 @@ describe('CSOT driver tests', () => { }); describe('when failing autoconnect with timeoutMS defined', () => { + let configClient: MongoClient; + beforeEach(async function () { - client = this.configuration.newClient(); - await client + configClient = this.configuration.newClient(); + await configClient + .db() + .admin() + .command({ + configureFailPoint: 'failCommand', + mode: 'alwaysOn', + data: { + failCommands: ['ping'], + blockConnection: true, + blockTimeMS: 10 + } + }); + }); + + afterEach(async function () { + await configClient .db() .admin() .command({ configureFailPoint: 'failCommand', - mode: { times: 1 }, + mode: 'off', data: { failCommands: ['ping'], blockConnection: true, blockTimeMS: 10 } }); - await client.close(); - client = undefined; + await configClient.close(); }); - it('throws a MongoOperationTimeoutError', async function () { - const commandsStarted = []; - client = this.configuration.newClient(undefined, { timeoutMS: 1, monitorCommands: true }); + it('throws a MongoOperationTimeoutError', { + metadata: { requires: { mongodb: '>=4.2' } }, + test: async function () { + const commandsStarted = []; + client = this.configuration.newClient(undefined, { timeoutMS: 1, monitorCommands: true }); - client.on('commandStarted', ev => commandsStarted.push(ev)); + client.on('commandStarted', ev => commandsStarted.push(ev)); - const maybeError = await client - .db('test') - .collection('test') - .insertOne({ a: 19 }) - .then( - () => null, - e => e - ); + const maybeError = await client + .db('test') + .collection('test') + .insertOne({ a: 19 }) + .then( + () => null, + e => e + ); - expect(commandsStarted).to.have.length(0); // Ensure that we fail before we start the insertOne + expect(commandsStarted).to.have.length(0); // Ensure that we fail before we start the insertOne - expect(maybeError).to.exist; - expect(maybeError).to.be.instanceof(MongoOperationTimeoutError); + expect(maybeError).to.exist; + expect(maybeError).to.be.instanceof(MongoOperationTimeoutError); + } }); }); });