Skip to content

Commit

Permalink
Merge pull request #14355 from 3150/introduce_resumeTokenChanged_into…
Browse files Browse the repository at this point in the history
…_6.x

Receive resumeTokenChanged changeStream event also in 6.x
  • Loading branch information
vkarpov15 committed Feb 22, 2024
2 parents 09181ef + 34feac0 commit 352137b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cursor/ChangeStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ChangeStream extends EventEmitter {
this.closed = true;
});

['close', 'change', 'end', 'error'].forEach(ev => {
['close', 'change', 'end', 'error', 'resumeTokenChanged'].forEach(ev => {
this.driverChangeStream.on(ev, data => {
// Sometimes Node driver still polls after close, so
// avoid any uncaught exceptions due to closed change streams
Expand Down
14 changes: 14 additions & 0 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5406,6 +5406,20 @@ describe('Model', function() {
assert.equal(changeData.operationType, 'insert');
assert.equal(changeData.fullDocument.name, 'Child');
});

it('bubbles up resumeTokenChanged events (gh-14349)', async function() {
const MyModel = db.model('Test', new Schema({ name: String }));

const resumeTokenChangedEvent = new Promise(resolve => {
changeStream = MyModel.watch();
listener = data => resolve(data);
changeStream.once('resumeTokenChanged', listener);
});

await MyModel.create({ name: 'test' });
const { _data } = await resumeTokenChangedEvent;
assert.ok(_data);
});
});

describe('sessions (gh-6362)', function() {
Expand Down

0 comments on commit 352137b

Please sign in to comment.