Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Receive resumeTokenChanged changeStream event also in 6.x #14355

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading