Skip to content

Commit b17136f

Browse files
Revert "refactor: clean up iterateUntilDocuemntOrError"
This reverts commit e492067.
1 parent e492067 commit b17136f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

test/tools/unified-spec-runner/operations.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,26 @@ operations.set('insertMany', async ({ entities, operation }) => {
303303
});
304304

305305
operations.set('iterateUntilDocumentOrError', async ({ entities, operation }) => {
306-
const cursorOrStream =
307-
entities.getEntity('stream', operation.object, false) ??
308-
entities.getEntity('cursor', operation.object, false);
306+
function getChangeStream(): UnifiedChangeStream | null {
307+
try {
308+
const changeStream = entities.getEntity('stream', operation.object);
309+
return changeStream;
310+
} catch (e) {
311+
return null;
312+
}
313+
}
309314

310-
if (cursorOrStream == null) {
311-
throw new Error(`Unable to get entity - expect stream or cursor but received ${operation}`);
315+
const changeStream = getChangeStream();
316+
if (changeStream == null) {
317+
// iterateUntilDocumentOrError is used for changes streams and regular cursors.
318+
// we have no other way to distinguish which scenario we are testing when we run an
319+
// iterateUntilDocumentOrError operation, so we first try to get the changeStream and
320+
// if that fails, we know we need to get a cursor
321+
const cursor = entities.getEntity('cursor', operation.object);
322+
return await cursor.next();
312323
}
313324

314-
return await cursorOrStream.next();
325+
return changeStream.next();
315326
});
316327

317328
operations.set('listCollections', async ({ entities, operation }) => {

0 commit comments

Comments
 (0)