@@ -21,9 +21,9 @@ import {
21
21
} from '../../mongodb' ;
22
22
import { getSymbolFrom , sleep } from '../../tools/utils' ;
23
23
import { TestConfiguration } from '../runner/config' ;
24
- import { EntitiesMap , UnifiedChangeStream } from './entities' ;
24
+ import { EntitiesMap } from './entities' ;
25
25
import { expectErrorCheck , resultCheck } from './match' ;
26
- import type { ExpectedEvent , ExpectedLogMessage , OperationDescription } from './schema' ;
26
+ import type { ExpectedEvent , OperationDescription } from './schema' ;
27
27
import { getMatchingEventCount , translateOptions } from './unified-utils' ;
28
28
29
29
interface OperationFunctionParams {
@@ -349,40 +349,14 @@ operations.set('insertMany', async ({ entities, operation }) => {
349
349
return collection . insertMany ( documents , opts ) ;
350
350
} ) ;
351
351
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
- }
360
352
operations . 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 ( ) ;
372
355
} ) ;
373
356
374
357
operations . 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 ( ) ;
386
360
} ) ;
387
361
388
362
operations . set ( 'listCollections' , async ( { entities, operation } ) => {
@@ -701,9 +675,7 @@ operations.set('createCommandCursor', async ({ entities, operation }: OperationF
701
675
702
676
// The spec dictates that we create the cursor and force the find command
703
677
// 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 ( ) ;
707
679
708
680
return cursor ;
709
681
} ) ;
0 commit comments