Skip to content

Commit d9206e8

Browse files
committed
test: fix failing tests
1 parent 232eaaa commit d9206e8

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/change_stream.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,13 +737,15 @@ export class ChangeStream<
737737
}, callback);
738738
}
739739

740-
async *[Symbol.asyncIterator](): AsyncGenerator<TChange, void, never> {
740+
async *[Symbol.asyncIterator](): AsyncGenerator<TChange, void, void> {
741741
if (this.closed) {
742742
return;
743743
}
744744

745745
try {
746-
while (await this.hasNext()) {
746+
// Change streams run indefinitely as long as errors are resumable
747+
// So the only loop breaking condition is if `next()` throws
748+
while (true) {
747749
yield await this.next();
748750
}
749751
} finally {

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,7 @@ describe('Change Streams', function () {
10131013
const docs = [{ city: 'New York City' }, { city: 'Seattle' }, { city: 'Boston' }];
10141014
await collection.insertMany(docs);
10151015

1016+
await changeStreamIterator.next();
10161017
await changeStreamIterator.return();
10171018
expect(changeStream.closed).to.be.true;
10181019
expect(changeStream.cursor.closed).to.be.true;
@@ -1074,12 +1075,8 @@ describe('Change Streams', function () {
10741075
changeStream.on('change', sinon.stub());
10751076
const changeStreamIterator = changeStream[Symbol.asyncIterator]();
10761077

1077-
try {
1078-
await changeStreamIterator.next();
1079-
expect.fail('Async iterator was used with emitter-based iteration');
1080-
} catch (error) {
1081-
expect(error).to.be.instanceOf(MongoAPIError);
1082-
}
1078+
const error = await changeStreamIterator.next().catch(e => e);
1079+
expect(error).to.be.instanceOf(MongoAPIError);
10831080
}
10841081
);
10851082

@@ -2465,15 +2462,10 @@ describe('ChangeStream resumability', function () {
24652462
} as FailPoint);
24662463

24672464
await collection.insertOne({ city: 'New York City' });
2468-
try {
2469-
await changeStreamIterator.next();
2470-
expect.fail(
2471-
'Change stream did not throw unresumable error and did not produce any events'
2472-
);
2473-
} catch (error) {
2474-
expect(error).to.be.instanceOf(MongoServerError);
2475-
expect(aggregateEvents).to.have.lengthOf(1);
2476-
}
2465+
2466+
const error = await changeStreamIterator.next().catch(e => e);
2467+
expect(error).to.be.instanceOf(MongoServerError);
2468+
expect(aggregateEvents).to.have.lengthOf(1);
24772469
}
24782470
);
24792471
});

0 commit comments

Comments
 (0)