Skip to content

Commit 298cc2e

Browse files
committed
test(NODE-3049): drivers atlas testing
1 parent f73d179 commit 298cc2e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

test/tools/unified-spec-runner/entity_event_registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const MAPPINGS = {
4040

4141
/**
4242
* Registers events that need to be stored in the entities map, since
43-
* the UnifiedMongoClient does not contain a ciclical dependency on the
43+
* the UnifiedMongoClient does not contain a cyclical dependency on the
4444
* entities map itself.
4545
*/
4646
export class EntityEventRegistry {

test/tools/unified-spec-runner/operations.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type Document,
1313
type GridFSFile,
1414
type MongoClient,
15+
MongoError,
1516
type ObjectId,
1617
ReadConcern,
1718
ReadPreference,
@@ -342,13 +343,22 @@ operations.set('failPoint', async ({ entities, operation }) => {
342343
operations.set('insertOne', async ({ entities, operation }) => {
343344
const collection = entities.getEntity('collection', operation.object);
344345
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);
346350
});
347351

348352
operations.set('insertMany', async ({ entities, operation }) => {
349353
const collection = entities.getEntity('collection', operation.object);
350354
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);
352362
});
353363

354364
operations.set('iterateUntilDocumentOrError', async ({ entities, operation }) => {
@@ -437,7 +447,8 @@ operations.set('loop', async ({ entities, operation, client, testConfig }) => {
437447
entities
438448
.getEntity('failures', storeFailuresAsEntity)
439449
.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.
441452
entities
442453
.getEntity('errors', storeErrorsAsEntity)
443454
.push({ error: error.message, time: Date.now() });

0 commit comments

Comments
 (0)