@@ -21,9 +21,9 @@ import {
2121} from '../../mongodb' ;
2222import { getSymbolFrom , sleep } from '../../tools/utils' ;
2323import { TestConfiguration } from '../runner/config' ;
24- import { EntitiesMap , UnifiedChangeStream } from './entities' ;
24+ import { EntitiesMap } from './entities' ;
2525import { expectErrorCheck , resultCheck } from './match' ;
26- import type { ExpectedEvent , ExpectedLogMessage , OperationDescription } from './schema' ;
26+ import type { ExpectedEvent , OperationDescription } from './schema' ;
2727import { getMatchingEventCount , translateOptions } from './unified-utils' ;
2828
2929interface OperationFunctionParams {
@@ -349,40 +349,14 @@ operations.set('insertMany', async ({ entities, operation }) => {
349349 return collection . insertMany ( documents , opts ) ;
350350} ) ;
351351
352- function getChangeStream ( { entities, operation } ) : UnifiedChangeStream | null {
353- try {
354- const changeStream = entities . getEntity ( 'stream' , operation . object ) ;
355- return changeStream ;
356- } catch ( e ) {
357- return null ;
358- }
359- }
360352operations . set ( 'iterateUntilDocumentOrError' , async ( { entities, operation } ) => {
361- const changeStream = getChangeStream ( { entities, operation } ) ;
362- if ( changeStream == null ) {
363- // iterateUntilDocumentOrError is used for changes streams and regular cursors.
364- // we have no other way to distinguish which scenario we are testing when we run an
365- // iterateUntilDocumentOrError operation, so we first try to get the changeStream and
366- // if that fails, we know we need to get a cursor
367- const cursor = entities . getEntity ( 'cursor' , operation . object ) ;
368- return cursor . next ( ) ;
369- }
370-
371- return changeStream . next ( ) ;
353+ const iterable = entities . getChangeStreamOrCursor ( operation . object ) ;
354+ return iterable . next ( ) ;
372355} ) ;
373356
374357operations . set ( 'iterateOnce' , async ( { entities, operation } ) => {
375- const changeStream = getChangeStream ( { entities, operation } ) ;
376- if ( changeStream == null ) {
377- // iterateOnce is used for changes streams and regular cursors.
378- // we have no other way to distinguish which scenario we are testing when we run an
379- // iterateOnce operation, so we first try to get the changeStream and
380- // if that fails, we know we need to get a cursor
381- const cursor = entities . getEntity ( 'cursor' , operation . object ) ;
382- return cursor . tryNext ( ) ;
383- }
384-
385- return changeStream . tryNext ( ) ;
358+ const iterable = entities . getChangeStreamOrCursor ( operation . object ) ;
359+ return iterable . tryNext ( ) ;
386360} ) ;
387361
388362operations . set ( 'listCollections' , async ( { entities, operation } ) => {
@@ -701,9 +675,7 @@ operations.set('createCommandCursor', async ({ entities, operation }: OperationF
701675
702676 // The spec dictates that we create the cursor and force the find command
703677 // to execute, but the first document must still be returned for the first iteration.
704- const result = await cursor . tryNext ( ) ;
705- const kDocuments = getSymbolFrom ( cursor , 'documents' ) ;
706- if ( result ) cursor [ kDocuments ] . unshift ( result ) ;
678+ await cursor . hasNext ( ) ;
707679
708680 return cursor ;
709681} ) ;
0 commit comments