@@ -12,6 +12,7 @@ import {
12
12
type Document ,
13
13
type GridFSFile ,
14
14
type MongoClient ,
15
+ MongoError ,
15
16
type ObjectId ,
16
17
ReadConcern ,
17
18
ReadPreference ,
@@ -342,13 +343,22 @@ operations.set('failPoint', async ({ entities, operation }) => {
342
343
operations . set ( 'insertOne' , async ( { entities, operation } ) => {
343
344
const collection = entities . getEntity ( 'collection' , operation . object ) ;
344
345
const { document, ...opts } = operation . arguments ! ;
345
- return collection . insertOne ( document , opts ) ;
346
+ // Looping exposes the fact that we can generate _ids for inserted
347
+ // documents and we don't want the original operation to get modified
348
+ // and use the same _id for each insert.
349
+ return collection . insertOne ( { ...document } , opts ) ;
346
350
} ) ;
347
351
348
352
operations . set ( 'insertMany' , async ( { entities, operation } ) => {
349
353
const collection = entities . getEntity ( 'collection' , operation . object ) ;
350
354
const { documents, ...opts } = operation . arguments ! ;
351
- return collection . insertMany ( documents , opts ) ;
355
+ // Looping exposes the fact that we can generate _ids for inserted
356
+ // documents and we don't want the original operation to get modified
357
+ // and use the same _id for each insert.
358
+ const clonedDocuments = documents . map ( doc => {
359
+ return { ...doc } ;
360
+ } ) ;
361
+ return collection . insertMany ( clonedDocuments , opts ) ;
352
362
} ) ;
353
363
354
364
operations . set ( 'iterateUntilDocumentOrError' , async ( { entities, operation } ) => {
@@ -437,7 +447,8 @@ operations.set('loop', async ({ entities, operation, client, testConfig }) => {
437
447
entities
438
448
. getEntity ( 'failures' , storeFailuresAsEntity )
439
449
. push ( { error : error . message , time : Date . now ( ) } ) ;
440
- } else if ( storeErrorsAsEntity ) {
450
+ } else if ( storeErrorsAsEntity && ! ( error instanceof MongoError ) ) {
451
+ // Checking not a MongoError ensures it's coming from the test runner.
441
452
entities
442
453
. getEntity ( 'errors' , storeErrorsAsEntity )
443
454
. push ( { error : error . message , time : Date . now ( ) } ) ;
0 commit comments