Skip to content

Commit

Permalink
test(NODE-3049): drivers atlas testing
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Aug 30, 2023
1 parent f73d179 commit 298cc2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/tools/unified-spec-runner/entity_event_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const MAPPINGS = {

/**
* Registers events that need to be stored in the entities map, since
* the UnifiedMongoClient does not contain a ciclical dependency on the
* the UnifiedMongoClient does not contain a cyclical dependency on the
* entities map itself.
*/
export class EntityEventRegistry {
Expand Down
17 changes: 14 additions & 3 deletions test/tools/unified-spec-runner/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
type Document,
type GridFSFile,
type MongoClient,
MongoError,
type ObjectId,
ReadConcern,
ReadPreference,
Expand Down Expand Up @@ -342,13 +343,22 @@ operations.set('failPoint', async ({ entities, operation }) => {
operations.set('insertOne', async ({ entities, operation }) => {
const collection = entities.getEntity('collection', operation.object);
const { document, ...opts } = operation.arguments!;
return collection.insertOne(document, opts);
// Looping exposes the fact that we can generate _ids for inserted
// documents and we don't want the original operation to get modified
// and use the same _id for each insert.
return collection.insertOne({ ...document }, opts);
});

operations.set('insertMany', async ({ entities, operation }) => {
const collection = entities.getEntity('collection', operation.object);
const { documents, ...opts } = operation.arguments!;
return collection.insertMany(documents, opts);
// Looping exposes the fact that we can generate _ids for inserted
// documents and we don't want the original operation to get modified
// and use the same _id for each insert.
const clonedDocuments = documents.map(doc => {
return { ...doc };
});
return collection.insertMany(clonedDocuments, opts);
});

operations.set('iterateUntilDocumentOrError', async ({ entities, operation }) => {
Expand Down Expand Up @@ -437,7 +447,8 @@ operations.set('loop', async ({ entities, operation, client, testConfig }) => {
entities
.getEntity('failures', storeFailuresAsEntity)
.push({ error: error.message, time: Date.now() });
} else if (storeErrorsAsEntity) {
} else if (storeErrorsAsEntity && !(error instanceof MongoError)) {
// Checking not a MongoError ensures it's coming from the test runner.
entities
.getEntity('errors', storeErrorsAsEntity)
.push({ error: error.message, time: Date.now() });
Expand Down

0 comments on commit 298cc2e

Please sign in to comment.