Skip to content

Commit db47396

Browse files
committed
fix flaky tests
1 parent c66dc7f commit db47396

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

test/integration/client-side-operations-timeout/node_csot.test.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,27 @@ import {
2222
MongoServerError
2323
} from '../../mongodb';
2424
import { type FailPoint } from '../../tools/utils';
25+
import { on } from 'node:events';
2526

2627
const metadata = { requires: { mongodb: '>=4.4' } };
2728

29+
2830
describe('CSOT driver tests', metadata, () => {
31+
const minPoolSize = 20;
32+
async function ensurePoolIsFull(client: MongoClient) {
33+
let connectionCount = 0;
34+
for await (const _ of on(client, 'connectionCreated')) {
35+
if (connectionCount++ >= minPoolSize) break;
36+
}
37+
}
38+
2939
describe('timeoutMS inheritance', () => {
3040
let client: MongoClient;
3141
let db: Db;
3242
let coll: Collection;
3343

3444
beforeEach(async function () {
35-
client = this.configuration.newClient(undefined, { timeoutMS: 100 });
45+
client = this.configuration.newClient(undefined, { timeoutMS: 100, minPoolSize });
3646
db = client.db('test', { timeoutMS: 200 });
3747
});
3848

@@ -576,7 +586,7 @@ describe('CSOT driver tests', metadata, () => {
576586
});
577587
});
578588

579-
describe('Tailable cursors', function () {
589+
describe.only('Tailable cursors', function () {
580590
let client: MongoClient;
581591
let internalClient: MongoClient;
582592
let commandStarted: CommandStartedEvent[];
@@ -611,9 +621,10 @@ describe('CSOT driver tests', metadata, () => {
611621

612622
await internalClient.db().admin().command(failpoint);
613623

614-
client = this.configuration.newClient(undefined, { monitorCommands: true });
624+
client = this.configuration.newClient(undefined, { monitorCommands: true, minPoolSize });
615625
commandStarted = [];
616626
client.on('commandStarted', ev => commandStarted.push(ev));
627+
await client.connect();
617628
});
618629

619630
afterEach(async function () {
@@ -739,9 +750,10 @@ describe('CSOT driver tests', metadata, () => {
739750

740751
await cursor.next();
741752

742-
expect(commandStarted).to.have.lengthOf(1);
743-
expect(commandStarted[0].command.find).to.exist;
744-
expect(commandStarted[0].command.maxTimeMS).to.not.exist;
753+
const finds = commandStarted.filter(x => x.command.find != null);
754+
expect(finds).to.have.lengthOf(1);
755+
expect(finds[0].command.find).to.exist;
756+
expect(finds[0].command.maxTimeMS).to.not.exist;
745757
});
746758
it('does not append a maxTimeMS field to subsequent getMores', async function () {
747759
cursor = client
@@ -752,9 +764,11 @@ describe('CSOT driver tests', metadata, () => {
752764
await cursor.next();
753765
await cursor.next();
754766

755-
expect(commandStarted).to.have.lengthOf(2);
756-
expect(commandStarted[1].command.getMore).to.exist;
757-
expect(commandStarted[0].command.maxTimeMS).to.not.exist;
767+
const getMores = commandStarted.filter(x => x.command.getMore != null);
768+
769+
expect(getMores).to.have.lengthOf(1);
770+
expect(getMores[0].command.getMore).to.exist;
771+
expect(getMores[0].command.getMore.maxTimeMS).to.not.exist;
758772
});
759773
});
760774
});

0 commit comments

Comments
 (0)