Skip to content

Commit 1d20d16

Browse files
committed
test(NODE-4763): add test for hasNext->next usage scenario
1 parent 4cafc42 commit 1d20d16

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,25 @@ describe('Change Streams', function () {
395395
expect(change).to.have.property('_id').that.deep.equals(changeStream.resumeToken);
396396
}
397397
});
398+
399+
it('should cache the resume token on an actual change, not on a probe', {
400+
metadata: { requires: { topology: 'replicaset' } },
401+
async test() {
402+
await initIteratorMode(changeStream);
403+
const resumeToken = changeStream.resumeToken;
404+
405+
await collection.insertOne({ a: 1 });
406+
407+
const hasNext = await changeStream.hasNext();
408+
expect(hasNext).to.be.true;
409+
410+
expect(changeStream.resumeToken).to.equal(resumeToken);
411+
412+
const change = await changeStream.next();
413+
expect(change).to.have.property('_id').that.deep.equals(changeStream.resumeToken);
414+
expect(resumeToken).to.not.equal(changeStream.resumeToken);
415+
}
416+
});
398417
});
399418

400419
it('should cache using event listener form', {
@@ -1847,6 +1866,8 @@ describe('Change Streams', function () {
18471866

18481867
changeStream = collection.watch([]);
18491868

1869+
// Configure a fail point with skip: 1 to simulate a server failure on the second `getMore`,
1870+
// triggering the resume process.
18501871
await client.db('admin').command({
18511872
configureFailPoint: is4_2Server(this.configuration.version)
18521873
? 'failCommand'

0 commit comments

Comments
 (0)