Skip to content

Commit aec0b97

Browse files
committed
test: fix failing tests
1 parent 30b7e10 commit aec0b97

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/change_stream.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -726,13 +726,15 @@ export class ChangeStream<
726726
}, callback);
727727
}
728728

729-
async *[Symbol.asyncIterator](): AsyncGenerator<TChange, void, never> {
729+
async *[Symbol.asyncIterator](): AsyncGenerator<TChange, void, void> {
730730
if (this.closed) {
731731
return;
732732
}
733733

734734
try {
735-
while (await this.hasNext()) {
735+
// Change streams run indefinitely as long as errors are resumable
736+
// So the only loop breaking condition is if `next()` throws
737+
while (true) {
736738
yield await this.next();
737739
}
738740
} finally {

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

+7-15
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

@@ -2406,15 +2403,10 @@ describe('ChangeStream resumability', function () {
24062403
} as FailPoint);
24072404

24082405
await collection.insertOne({ city: 'New York City' });
2409-
try {
2410-
await changeStreamIterator.next();
2411-
expect.fail(
2412-
'Change stream did not throw unresumable error and did not produce any events'
2413-
);
2414-
} catch (error) {
2415-
expect(error).to.be.instanceOf(MongoServerError);
2416-
expect(aggregateEvents).to.have.lengthOf(1);
2417-
}
2406+
2407+
const error = await changeStreamIterator.next().catch(e => e);
2408+
expect(error).to.be.instanceOf(MongoServerError);
2409+
expect(aggregateEvents).to.have.lengthOf(1);
24182410
}
24192411
);
24202412
});

0 commit comments

Comments
 (0)