Skip to content

Commit

Permalink
ensure test only runs when failcommand is available
Browse files Browse the repository at this point in the history
  • Loading branch information
W-A-James committed May 24, 2024
1 parent bab1667 commit 4d126eb
Showing 1 changed file with 39 additions and 20 deletions.
59 changes: 39 additions & 20 deletions test/integration/client-side-operations-timeout/node_csot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
});
Expand Down

0 comments on commit 4d126eb

Please sign in to comment.