Skip to content

Commit e5fef5b

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

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
@@ -309,15 +309,26 @@ operations.set('insertMany', async ({ entities, operation }) => {
309309
});
310310

311311
operations.set('iterateUntilDocumentOrError', async ({ entities, operation }) => {
312-
const cursorOrStream =
313-
entities.getEntity('stream', operation.object, false) ??
314-
entities.getEntity('cursor', operation.object, false);
312+
function getChangeStream(): UnifiedChangeStream | null {
313+
try {
314+
const changeStream = entities.getEntity('stream', operation.object);
315+
return changeStream;
316+
} catch (e) {
317+
return null;
318+
}
319+
}
315320

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

320-
return await cursorOrStream.next();
331+
return changeStream.next();
321332
});
322333

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

0 commit comments

Comments
 (0)