Skip to content

Commit c2b8b24

Browse files
committed
implement prose tests
1 parent e6aa06b commit c2b8b24

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

test/integration/client-side-operations-timeout/client_side_operations_timeout.prose.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import { expect } from 'chai';
44
import * as sinon from 'sinon';
55

6+
import { type CommandStartedEvent } from '../../../mongodb';
67
import {
8+
type CommandSucceededEvent,
79
MongoClient,
810
MongoOperationTimeoutError,
911
MongoServerSelectionError,
1012
now
1113
} from '../../mongodb';
14+
import { type FailPoint } from '../../tools/utils';
1215

1316
// TODO(NODE-5824): Implement CSOT prose tests
1417
describe('CSOT spec prose tests', function () {
@@ -220,6 +223,42 @@ describe('CSOT spec prose tests', function () {
220223
* blocking method for cursor iteration that executes `getMore` commands in a loop until a document is available or an
221224
* error occurs.
222225
*/
226+
const failpoint: FailPoint = {
227+
configureFailPoint: 'failCommand',
228+
mode: 'alwaysOn',
229+
data: {
230+
failCommands: ['getMore'],
231+
blockConnection: true,
232+
blockTimeMS: 15
233+
}
234+
};
235+
let internalClient: MongoClient;
236+
let client: MongoClient;
237+
let commandStarted: CommandStartedEvent[];
238+
let commandSucceeded: CommandSucceededEvent[];
239+
240+
beforeEach(async function () {
241+
internalClient = this.configuration.newClient();
242+
await internalClient.db('db').dropCollection('coll');
243+
await internalClient.db('db').collection('coll').insertOne({ x: 1 });
244+
await internalClient.db().admin().command(failpoint);
245+
246+
client = this.configuration.newClient(undefined, { timeoutMS: 20 });
247+
commandStarted = [];
248+
commandSucceeded = [];
249+
250+
client.on('commandStarted', ev => commandStarted.push(ev));
251+
client.on('commandSucceeded', ev => commandSucceeded.push(ev));
252+
});
253+
254+
afterEach(async function () {
255+
await internalClient
256+
.db()
257+
.admin()
258+
.command({ ...failpoint, mode: 'off' });
259+
await internalClient.close();
260+
await client.close();
261+
});
223262

224263
context('Tailable cursors', () => {
225264
/**
@@ -246,6 +285,27 @@ describe('CSOT spec prose tests', function () {
246285
* - Expect this to fail with a timeout error.
247286
* 1. Verify that a `find` command and two `getMore` commands were executed against the `db.coll` collection during the test.
248287
*/
288+
289+
it('send correct number of finds and getMores', async function () {
290+
const cursor = client.db('db').collection('coll').find({}, { tailable: true });
291+
const doc = await cursor.next();
292+
// FIXME: Account for object id
293+
expect(doc).to.deep.equal({ x: 1 });
294+
// Check that there are no getMores sent
295+
expect(commandStarted.filter(e => Object.hasOwn(e.command, 'getMore'))).to.have.lengthOf(0);
296+
297+
const maybeError = await cursor.next().then(
298+
() => null,
299+
e => e
300+
);
301+
302+
expect(maybeError).to.be.instanceof(MongoOperationTimeoutError);
303+
expect(
304+
commandStarted.filter(
305+
e => Object.hasOwn(e.command, 'find') || Object.hasOwn(e.command, 'getMore')
306+
)
307+
).to.have.lengthOf(3);
308+
});
249309
});
250310

251311
context('Change Streams', () => {
@@ -270,6 +330,20 @@ describe('CSOT spec prose tests', function () {
270330
* - Expect this to fail with a timeout error.
271331
* 1. Verify that an `aggregate` command and two `getMore` commands were executed against the `db.coll` collection during the test.
272332
*/
333+
it('sends correct number of aggregate and getMores', async function () {
334+
const changeStream = client.db('db').collection('coll').watch();
335+
const maybeError = await changeStream.next().then(
336+
() => null,
337+
e => e
338+
);
339+
340+
expect(maybeError).to.be.instanceof(MongoOperationTimeoutError);
341+
expect(
342+
commandStarted.filter(
343+
e => Object.hasOwn(e.command, 'aggregate') || Object.hasOwn(e.command, 'getMore')
344+
)
345+
).to.have.lengthOf(3);
346+
});
273347
});
274348
});
275349

0 commit comments

Comments
 (0)