Skip to content

Commit 67cca6f

Browse files
committed
fix: got all tests working
1 parent 119bb39 commit 67cca6f

File tree

2 files changed

+17
-44
lines changed

2 files changed

+17
-44
lines changed

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

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -451,56 +451,28 @@ describe('Change Streams', function () {
451451
});
452452
});
453453

454-
it.only('should error if resume token projected out of change stream document using iterator', {
454+
it('should error if resume token projected out of change stream document using iterator', {
455455
metadata: { requires: { topology: 'replicaset' } },
456-
test(done) {
456+
async test() {
457457
const configuration = this.configuration;
458458
const client = configuration.newClient();
459459

460-
console.log(`pavel >>> 1 before all`);
461-
462-
client.connect((err, client) => {
463-
expect(err).to.not.exist;
460+
await client.connect();
464461

465-
console.log(`pavel >>> 2 after connect`);
462+
const database = client.db('integration_tests');
463+
const collection = database.collection('resumetokenProjectedOutCallback');
464+
const changeStream = collection.watch([{ $project: { _id: false } }]);
466465

467-
const database = client.db('integration_tests');
468-
const collection = database.collection('resumetokenProjectedOutCallback');
469-
const changeStream = collection.watch([{ $project: { _id: false } }]);
466+
await initIteratorMode(changeStream);
470467

471-
console.log(`pavel >>> 3 before hasNext`);
468+
const res = await collection.insertOne({ b: 2 });
469+
expect(res).to.exist;
472470

473-
changeStream.hasNext(() => {
474-
// trigger initialize
475-
console.log(`pavel >>> ? trigger initialize?`);
476-
});
477-
478-
console.log(`pavel >>> 4 after hasNext`);
479-
480-
changeStream.cursor.on('init', () => {
481-
console.log(`pavel >>> 5 init`);
482-
collection.insertOne({ b: 2 }, (err, res) => {
483-
console.log(`pavel >>> 6 after insertOne`);
484-
expect(err).to.be.undefined;
485-
expect(res).to.exist;
486-
487-
console.log(`pavel >>> 7 before next`);
488-
changeStream.next(err => {
489-
console.log(`pavel >>> 8 after next`);
490-
expect(err).to.exist;
491-
console.log(`pavel >>> 9 before close`);
492-
changeStream.close(() => {
493-
console.log(`pavel >>> 10 after close change stream`);
494-
client.close(() => {
495-
console.log(`pavel >>> 11 after close client`);
496-
console.log("pavel >>> DONE");
497-
done();
498-
});
499-
});
500-
});
501-
});
502-
});
503-
});
471+
const err = await changeStream.next().catch(e => e);
472+
expect(err).to.exist;
473+
console.log(`pavel >>> ${JSON.stringify(err)}`);
474+
await changeStream.close();
475+
await client.close();
504476
}
505477
});
506478

test/integration/change-streams/change_streams.prose.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,9 @@ describe('Change Stream prose tests', function () {
632632
let events = [];
633633
client.on('commandStarted', e => recordEvent(events, e));
634634
const changeStream = coll.watch([], { startAfter });
635-
// changeStream.on('error', done);
636-
// this.defer(() => changeStream.close());
635+
changeStream.on('error', async () => {
636+
await changeStream.close();
637+
});
637638

638639
changeStream.on('change', change => {
639640
events.push({ change: { insert: { x: change.fullDocument.x } } });

0 commit comments

Comments
 (0)