Skip to content

Commit cd4f6c0

Browse files
committed
test(NODE-4763): add tests for resumeToken caching mechanism
1 parent 4a6447c commit cd4f6c0

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

test/integration/change-streams/change_stream.test.ts

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const pipeline = [
4545
{ $addFields: { comment: 'The documentKey field has been projected out of this document.' } }
4646
];
4747

48-
describe('Change Streams', function () {
48+
describe.only('Change Streams', function () {
4949
let client: MongoClient;
5050
let collection: Collection;
5151
let changeStream: ChangeStream;
@@ -370,31 +370,50 @@ describe('Change Streams', function () {
370370
}
371371
);
372372

373-
it('should cache the change stream resume token using iterator form', {
374-
metadata: { requires: { topology: 'replicaset' } },
373+
describe('cache the change stream resume token', () => {
374+
describe('using iterator form', () => {
375+
it('#next', {
376+
metadata: { requires: { topology: 'replicaset' } },
375377

376-
async test() {
377-
await initIteratorMode(changeStream);
378-
collection.insertOne({ a: 1 });
378+
async test() {
379+
await initIteratorMode(changeStream);
380+
collection.insertOne({ a: 1 });
379381

380-
const hasNext = await changeStream.hasNext();
381-
expect(hasNext).to.be.true;
382+
const hasNext = await changeStream.hasNext();
383+
expect(hasNext).to.be.true;
382384

383-
const change = await changeStream.next();
384-
expect(change).to.have.property('_id').that.deep.equals(changeStream.resumeToken);
385-
}
386-
});
385+
const change = await changeStream.next();
386+
expect(change).to.have.property('_id').that.deep.equals(changeStream.resumeToken);
387+
}
388+
});
387389

388-
it('should cache the change stream resume token using event listener form', {
389-
metadata: { requires: { topology: 'replicaset' } },
390-
async test() {
391-
const willBeChange = once(changeStream, 'change');
392-
await once(changeStream.cursor, 'init');
393-
collection.insertOne({ a: 1 });
390+
it('#tryNext', {
391+
metadata: { requires: { topology: 'replicaset' } },
394392

395-
const [change] = await willBeChange;
396-
expect(change).to.have.property('_id').that.deep.equals(changeStream.resumeToken);
397-
}
393+
async test() {
394+
await initIteratorMode(changeStream);
395+
collection.insertOne({ a: 1 });
396+
397+
const hasNext = await changeStream.hasNext();
398+
expect(hasNext).to.be.true;
399+
400+
const change = await changeStream.tryNext();
401+
expect(change).to.have.property('_id').that.deep.equals(changeStream.resumeToken);
402+
}
403+
});
404+
});
405+
406+
it('should cache using event listener form', {
407+
metadata: { requires: { topology: 'replicaset' } },
408+
async test() {
409+
const willBeChange = once(changeStream, 'change');
410+
await once(changeStream.cursor, 'init');
411+
collection.insertOne({ a: 1 });
412+
413+
const [change] = await willBeChange;
414+
expect(change).to.have.property('_id').that.deep.equals(changeStream.resumeToken);
415+
}
416+
});
398417
});
399418

400419
it('should error if resume token projected out of change stream document using iterator', {

0 commit comments

Comments
 (0)