@@ -58,7 +58,7 @@ operations.set('aggregate', async ({ entities, operation }) => {
58
58
}
59
59
const { pipeline, ...opts } = operation . arguments ! ;
60
60
const cursor = dbOrCollection . aggregate ( pipeline , opts ) ;
61
- return cursor . toArray ( ) ;
61
+ return await cursor . toArray ( ) ;
62
62
} ) ;
63
63
64
64
operations . set ( 'assertCollectionExists' , async ( { operation, client } ) => {
@@ -196,7 +196,7 @@ operations.set('assertNumberConnectionsCheckedOut', async ({ entities, operation
196
196
operations . set ( 'bulkWrite' , async ( { entities, operation } ) => {
197
197
const collection = entities . getEntity ( 'collection' , operation . object ) ;
198
198
const { requests, ...opts } = operation . arguments ! ;
199
- return collection . bulkWrite ( requests , opts ) ;
199
+ return await collection . bulkWrite ( requests , opts ) ;
200
200
} ) ;
201
201
202
202
operations . set ( 'clientBulkWrite' , async ( { entities, operation } ) => {
@@ -206,7 +206,7 @@ operations.set('clientBulkWrite', async ({ entities, operation }) => {
206
206
const name = Object . keys ( model ) [ 0 ] ;
207
207
return { name : name , ...model [ name ] } ;
208
208
} ) ;
209
- return client . bulkWrite ( bulkWriteModels , opts ) ;
209
+ return await client . bulkWrite ( bulkWriteModels , opts ) ;
210
210
} ) ;
211
211
212
212
// The entity exists for the name but can potentially have the wrong
@@ -303,7 +303,7 @@ operations.set('dropIndex', async ({ entities, operation }) => {
303
303
operations . set ( 'deleteOne' , async ( { entities, operation } ) => {
304
304
const collection = entities . getEntity ( 'collection' , operation . object ) ;
305
305
const { filter, ...options } = operation . arguments ! ;
306
- return collection . deleteOne ( filter , options ) ;
306
+ return await collection . deleteOne ( filter , options ) ;
307
307
} ) ;
308
308
309
309
operations . set ( 'dropCollection' , async ( { entities, operation } ) => {
@@ -323,17 +323,17 @@ operations.set('dropCollection', async ({ entities, operation }) => {
323
323
324
324
operations . set ( 'drop' , async ( { entities, operation } ) => {
325
325
const bucket = entities . getEntity ( 'bucket' , operation . object ) ;
326
- return bucket . drop ( operation . arguments ) ;
326
+ return await bucket . drop ( operation . arguments ) ;
327
327
} ) ;
328
328
329
329
operations . set ( 'dropIndexes' , async ( { entities, operation } ) => {
330
330
const collection = entities . getEntity ( 'collection' , operation . object ) ;
331
- return collection . dropIndexes ( operation . arguments ) ;
331
+ return await collection . dropIndexes ( operation . arguments ) ;
332
332
} ) ;
333
333
334
334
operations . set ( 'endSession' , async ( { entities, operation } ) => {
335
335
const session = entities . getEntity ( 'session' , operation . object ) ;
336
- return session . endSession ( ) ;
336
+ return await session . endSession ( ) ;
337
337
} ) ;
338
338
339
339
operations . set ( 'find' , async ( { entities, operation } ) => {
@@ -355,36 +355,36 @@ operations.set('find', async ({ entities, operation }) => {
355
355
default :
356
356
break ;
357
357
}
358
- return queryable . find ( filter , opts ) . toArray ( ) ;
358
+ return await queryable . find ( filter , opts ) . toArray ( ) ;
359
359
} ) ;
360
360
361
361
operations . set ( 'findOne' , async ( { entities, operation } ) => {
362
362
const collection = entities . getEntity ( 'collection' , operation . object ) ;
363
363
const { filter, ...opts } = operation . arguments ! ;
364
- return collection . findOne ( filter , opts ) ;
364
+ return await collection . findOne ( filter , opts ) ;
365
365
} ) ;
366
366
367
367
operations . set ( 'findOneAndReplace' , async ( { entities, operation } ) => {
368
368
const collection = entities . getEntity ( 'collection' , operation . object ) ;
369
369
const { filter, replacement, ...opts } = operation . arguments ! ;
370
- return collection . findOneAndReplace ( filter , replacement , translateOptions ( opts ) ) ;
370
+ return await collection . findOneAndReplace ( filter , replacement , translateOptions ( opts ) ) ;
371
371
} ) ;
372
372
373
373
operations . set ( 'findOneAndUpdate' , async ( { entities, operation } ) => {
374
374
const collection = entities . getEntity ( 'collection' , operation . object ) ;
375
375
const { filter, update, ...opts } = operation . arguments ! ;
376
- return collection . findOneAndUpdate ( filter , update , translateOptions ( opts ) ) ;
376
+ return await collection . findOneAndUpdate ( filter , update , translateOptions ( opts ) ) ;
377
377
} ) ;
378
378
379
379
operations . set ( 'findOneAndDelete' , async ( { entities, operation } ) => {
380
380
const collection = entities . getEntity ( 'collection' , operation . object ) ;
381
381
const { filter, ...opts } = operation . arguments ! ;
382
- return collection . findOneAndDelete ( filter , opts ) ;
382
+ return await collection . findOneAndDelete ( filter , opts ) ;
383
383
} ) ;
384
384
385
385
operations . set ( 'failPoint' , async ( { entities, operation } ) => {
386
386
const client = entities . getEntity ( 'client' , operation . arguments ! . client ) ;
387
- return entities . failPoints . enableFailPoint ( client , operation . arguments ! . failPoint ) ;
387
+ return await entities . failPoints . enableFailPoint ( client , operation . arguments ! . failPoint ) ;
388
388
} ) ;
389
389
390
390
operations . set ( 'insertOne' , async ( { entities, operation } ) => {
@@ -408,23 +408,23 @@ operations.set('insertMany', async ({ entities, operation }) => {
408
408
const clonedDocuments = documents . map ( doc => {
409
409
return { ...doc } ;
410
410
} ) ;
411
- return collection . insertMany ( clonedDocuments , opts ) ;
411
+ return await collection . insertMany ( clonedDocuments , opts ) ;
412
412
} ) ;
413
413
414
414
operations . set ( 'iterateUntilDocumentOrError' , async ( { entities, operation } ) => {
415
415
const iterable = entities . getChangeStreamOrCursor ( operation . object ) ;
416
- return iterable . next ( ) ;
416
+ return await iterable . next ( ) ;
417
417
} ) ;
418
418
419
419
operations . set ( 'iterateOnce' , async ( { entities, operation } ) => {
420
420
const iterable = entities . getChangeStreamOrCursor ( operation . object ) ;
421
- return iterable . tryNext ( ) ;
421
+ return await iterable . tryNext ( ) ;
422
422
} ) ;
423
423
424
424
operations . set ( 'listCollections' , async ( { entities, operation } ) => {
425
425
const db = entities . getEntity ( 'db' , operation . object ) ;
426
426
const { filter, ...opts } = operation . arguments ?? { filter : { } } ;
427
- return db . listCollections ( filter , opts ) . toArray ( ) ;
427
+ return await db . listCollections ( filter , opts ) . toArray ( ) ;
428
428
} ) ;
429
429
430
430
operations . set ( 'listCollectionNames' , async ( { entities, operation } ) => {
@@ -436,7 +436,7 @@ operations.set('listCollectionNames', async ({ entities, operation }) => {
436
436
437
437
operations . set ( 'listDatabases' , async ( { entities, operation } ) => {
438
438
const client = entities . getEntity ( 'client' , operation . object ) ;
439
- return client . db ( ) . admin ( ) . listDatabases ( operation . arguments ! ) ;
439
+ return await client . db ( ) . admin ( ) . listDatabases ( operation . arguments ! ) ;
440
440
} ) ;
441
441
442
442
operations . set ( 'listDatabaseNames' , async ( { entities, operation } ) => {
@@ -447,7 +447,7 @@ operations.set('listDatabaseNames', async ({ entities, operation }) => {
447
447
448
448
operations . set ( 'listIndexes' , async ( { entities, operation } ) => {
449
449
const collection = entities . getEntity ( 'collection' , operation . object ) ;
450
- return collection . listIndexes ( operation . arguments ! ) . toArray ( ) ;
450
+ return await collection . listIndexes ( operation . arguments ! ) . toArray ( ) ;
451
451
} ) ;
452
452
453
453
operations . set ( 'listIndexNames' , async ( { entities, operation } ) => {
@@ -532,7 +532,7 @@ operations.set('loop', async ({ entities, operation, client, testConfig }) => {
532
532
operations . set ( 'replaceOne' , async ( { entities, operation } ) => {
533
533
const collection = entities . getEntity ( 'collection' , operation . object ) ;
534
534
const { filter, replacement, ...opts } = operation . arguments ! ;
535
- return collection . replaceOne ( filter , replacement , opts ) ;
535
+ return await collection . replaceOne ( filter , replacement , opts ) ;
536
536
} ) ;
537
537
538
538
operations . set ( 'startTransaction' , async ( { entities, operation } ) => {
@@ -553,7 +553,7 @@ operations.set('targetedFailPoint', async ({ entities, operation }) => {
553
553
operations . set ( 'delete' , async ( { entities, operation } ) => {
554
554
const bucket = entities . getEntity ( 'bucket' , operation . object ) ;
555
555
const { id, ...opts } = operation . arguments ;
556
- return bucket . delete ( id , opts ) ;
556
+ return await bucket . delete ( id , opts ) ;
557
557
} ) ;
558
558
559
559
operations . set ( 'download' , async ( { entities, operation } ) => {
@@ -765,30 +765,30 @@ operations.set('withTransaction', async ({ entities, operation, client, testConf
765
765
operations . set ( 'count' , async ( { entities, operation } ) => {
766
766
const collection = entities . getEntity ( 'collection' , operation . object ) ;
767
767
const { filter, ...opts } = operation . arguments ! ;
768
- return collection . count ( filter , opts ) ;
768
+ return await collection . count ( filter , opts ) ;
769
769
} ) ;
770
770
771
771
operations . set ( 'countDocuments' , async ( { entities, operation } ) => {
772
772
const collection = entities . getEntity ( 'collection' , operation . object ) ;
773
773
const { filter, ...opts } = operation . arguments ! ;
774
- return collection . countDocuments ( filter , opts ) ;
774
+ return await collection . countDocuments ( filter , opts ) ;
775
775
} ) ;
776
776
777
777
operations . set ( 'deleteMany' , async ( { entities, operation } ) => {
778
778
const collection = entities . getEntity ( 'collection' , operation . object ) ;
779
779
const { filter, ...opts } = operation . arguments ! ;
780
- return collection . deleteMany ( filter , opts ) ;
780
+ return await collection . deleteMany ( filter , opts ) ;
781
781
} ) ;
782
782
783
783
operations . set ( 'distinct' , async ( { entities, operation } ) => {
784
784
const collection = entities . getEntity ( 'collection' , operation . object ) ;
785
785
const { fieldName, filter, ...opts } = operation . arguments ! ;
786
- return collection . distinct ( fieldName , filter , opts ) ;
786
+ return await collection . distinct ( fieldName , filter , opts ) ;
787
787
} ) ;
788
788
789
789
operations . set ( 'estimatedDocumentCount' , async ( { entities, operation } ) => {
790
790
const collection = entities . getEntity ( 'collection' , operation . object ) ;
791
- return collection . estimatedDocumentCount ( operation . arguments ! ) ;
791
+ return await collection . estimatedDocumentCount ( operation . arguments ! ) ;
792
792
} ) ;
793
793
794
794
operations . set ( 'runCommand' , async ( { entities, operation } : OperationFunctionParams ) => {
@@ -804,7 +804,7 @@ operations.set('runCommand', async ({ entities, operation }: OperationFunctionPa
804
804
timeoutMS : operation . arguments . timeoutMS
805
805
} ;
806
806
807
- return db . command ( command , options ) ;
807
+ return await db . command ( command , options ) ;
808
808
} ) ;
809
809
810
810
operations . set ( 'runCursorCommand' , async ( { entities, operation } : OperationFunctionParams ) => {
@@ -821,7 +821,7 @@ operations.set('runCursorCommand', async ({ entities, operation }: OperationFunc
821
821
if ( ! Number . isNaN ( + opts . maxTimeMS ) ) cursor . setMaxTimeMS ( + opts . maxTimeMS ) ;
822
822
if ( opts . comment !== undefined ) cursor . setComment ( opts . comment ) ;
823
823
824
- return cursor . toArray ( ) ;
824
+ return await cursor . toArray ( ) ;
825
825
} ) ;
826
826
827
827
operations . set ( 'createCommandCursor' , async ( { entities, operation } : OperationFunctionParams ) => {
@@ -861,13 +861,13 @@ operations.set('createCommandCursor', async ({ entities, operation }: OperationF
861
861
operations . set ( 'updateMany' , async ( { entities, operation } ) => {
862
862
const collection = entities . getEntity ( 'collection' , operation . object ) ;
863
863
const { filter, update, ...options } = operation . arguments ! ;
864
- return collection . updateMany ( filter , update , options ) ;
864
+ return await collection . updateMany ( filter , update , options ) ;
865
865
} ) ;
866
866
867
867
operations . set ( 'updateOne' , async ( { entities, operation } ) => {
868
868
const collection = entities . getEntity ( 'collection' , operation . object ) ;
869
869
const { filter, update, ...options } = operation . arguments ! ;
870
- return collection . updateOne ( filter , update , options ) ;
870
+ return await collection . updateOne ( filter , update , options ) ;
871
871
} ) ;
872
872
873
873
operations . set ( 'rename' , async ( { entities, operation } ) => {
@@ -880,7 +880,7 @@ operations.set('rename', async ({ entities, operation }) => {
880
880
881
881
if ( entity instanceof Collection ) {
882
882
const { to, ...options } = operation . arguments ! ;
883
- return entity . rename ( to , options ) ;
883
+ return await entity . rename ( to , options ) ;
884
884
}
885
885
886
886
try {
@@ -891,7 +891,7 @@ operations.set('rename', async ({ entities, operation }) => {
891
891
892
892
if ( entity instanceof GridFSBucket ) {
893
893
const { id, newFilename, ...opts } = operation . arguments ! ;
894
- return entity . rename ( id , newFilename , opts as any ) ;
894
+ return await entity . rename ( id , newFilename , opts as any ) ;
895
895
}
896
896
897
897
expect . fail ( `No collection or bucket with name '${ operation . object } ' found` ) ;
@@ -901,7 +901,7 @@ operations.set('createDataKey', async ({ entities, operation }) => {
901
901
const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
902
902
const { kmsProvider, opts } = operation . arguments ! ;
903
903
904
- return clientEncryption . createDataKey ( kmsProvider , opts ) ;
904
+ return await clientEncryption . createDataKey ( kmsProvider , opts ) ;
905
905
} ) ;
906
906
907
907
operations . set ( 'rewrapManyDataKey' , async ( { entities, operation } ) => {
@@ -915,85 +915,85 @@ operations.set('deleteKey', async ({ entities, operation }) => {
915
915
const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
916
916
const { id } = operation . arguments ! ;
917
917
918
- return clientEncryption . deleteKey ( id ) ;
918
+ return await clientEncryption . deleteKey ( id ) ;
919
919
} ) ;
920
920
921
921
operations . set ( 'getKey' , async ( { entities, operation } ) => {
922
922
const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
923
923
const { id } = operation . arguments ! ;
924
924
925
- return clientEncryption . getKey ( id ) ;
925
+ return await clientEncryption . getKey ( id ) ;
926
926
} ) ;
927
927
928
928
operations . set ( 'getKeys' , async ( { entities, operation } ) => {
929
929
const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
930
930
931
- return clientEncryption . getKeys ( ) . toArray ( ) ;
931
+ return await clientEncryption . getKeys ( ) . toArray ( ) ;
932
932
} ) ;
933
933
934
934
operations . set ( 'addKeyAltName' , async ( { entities, operation } ) => {
935
935
const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
936
936
const { id, keyAltName } = operation . arguments ! ;
937
937
938
- return clientEncryption . addKeyAltName ( id , keyAltName ) ;
938
+ return await clientEncryption . addKeyAltName ( id , keyAltName ) ;
939
939
} ) ;
940
940
941
941
operations . set ( 'removeKeyAltName' , async ( { entities, operation } ) => {
942
942
const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
943
943
const { id, keyAltName } = operation . arguments ! ;
944
944
945
- return clientEncryption . removeKeyAltName ( id , keyAltName ) ;
945
+ return await clientEncryption . removeKeyAltName ( id , keyAltName ) ;
946
946
} ) ;
947
947
948
948
operations . set ( 'getKeyByAltName' , async ( { entities, operation } ) => {
949
949
const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
950
950
const { keyAltName } = operation . arguments ?? { } ;
951
951
952
- return clientEncryption . getKeyByAltName ( keyAltName ) ;
952
+ return await clientEncryption . getKeyByAltName ( keyAltName ) ;
953
953
} ) ;
954
954
955
955
operations . set ( 'encrypt' , async ( { entities, operation } ) => {
956
956
const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
957
957
const { value, opts } = operation . arguments ?? { } ;
958
958
959
- return clientEncryption . encrypt ( value , opts ) ;
959
+ return await clientEncryption . encrypt ( value , opts ) ;
960
960
} ) ;
961
961
962
962
operations . set ( 'decrypt' , async ( { entities, operation } ) => {
963
963
const clientEncryption = entities . getEntity ( 'clientEncryption' , operation . object ) ;
964
964
const { value } = operation . arguments ?? { } ;
965
965
966
- return clientEncryption . decrypt ( value ) ;
966
+ return await clientEncryption . decrypt ( value ) ;
967
967
} ) ;
968
968
969
969
operations . set ( 'listSearchIndexes' , async ( { entities, operation } ) => {
970
970
const collection : Collection < any > = entities . getEntity ( 'collection' , operation . object ) ;
971
971
const { name, aggregationOptions } = operation . arguments ?? { } ;
972
- return collection . listSearchIndexes ( name , aggregationOptions ) . toArray ( ) ;
972
+ return await collection . listSearchIndexes ( name , aggregationOptions ) . toArray ( ) ;
973
973
} ) ;
974
974
975
975
operations . set ( 'dropSearchIndex' , async ( { entities, operation } ) => {
976
976
const collection : Collection < any > = entities . getEntity ( 'collection' , operation . object ) ;
977
977
const { name } = operation . arguments ?? { } ;
978
- return collection . dropSearchIndex ( name ) ;
978
+ return await collection . dropSearchIndex ( name ) ;
979
979
} ) ;
980
980
981
981
operations . set ( 'updateSearchIndex' , async ( { entities, operation } ) => {
982
982
const collection : Collection < any > = entities . getEntity ( 'collection' , operation . object ) ;
983
983
const { name, definition } = operation . arguments ?? { } ;
984
- return collection . updateSearchIndex ( name , definition ) ;
984
+ return await collection . updateSearchIndex ( name , definition ) ;
985
985
} ) ;
986
986
987
987
operations . set ( 'createSearchIndex' , async ( { entities, operation } ) => {
988
988
const collection : Collection < any > = entities . getEntity ( 'collection' , operation . object ) ;
989
989
const { model } = operation . arguments ?? { } ;
990
- return collection . createSearchIndex ( model ) ;
990
+ return await collection . createSearchIndex ( model ) ;
991
991
} ) ;
992
992
993
993
operations . set ( 'createSearchIndexes' , async ( { entities, operation } ) => {
994
994
const collection : Collection < any > = entities . getEntity ( 'collection' , operation . object ) ;
995
995
const { models } = operation . arguments ?? { } ;
996
- return collection . createSearchIndexes ( models ) ;
996
+ return await collection . createSearchIndexes ( models ) ;
997
997
} ) ;
998
998
999
999
operations . set ( 'modifyCollection' , async ( { entities, operation } ) => {
@@ -1002,9 +1002,14 @@ operations.set('modifyCollection', async ({ entities, operation }) => {
1002
1002
collMod : operation . arguments ?. collection ,
1003
1003
validator : operation . arguments ?. validator
1004
1004
} ;
1005
- return db . command ( command , { } ) ;
1005
+ return await db . command ( command , { } ) ;
1006
1006
} ) ;
1007
1007
1008
+ // make function name appear in stack trace
1009
+ operations . forEach ( ( fn , name ) =>
1010
+ Object . defineProperty ( fn , 'name' , { value : name , configurable : true } )
1011
+ ) ;
1012
+
1008
1013
export async function executeOperationAndCheck (
1009
1014
operation : OperationDescription ,
1010
1015
entities : EntitiesMap ,
0 commit comments