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 24, 2023
1 parent a17b0af commit 6dbbe8d
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"check:unit": "mocha test/unit",
"check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",
"check:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.js",
"check:drivers-atlas-testing": "mocha --config test/mocha_mongodb.json test/atlas/drivers_atlas_testing.test.ts",
"check:adl": "mocha --config test/mocha_mongodb.json test/manual/atlas-data-lake-testing",
"check:aws": "nyc mocha --config test/mocha_mongodb.json test/integration/auth/mongodb_aws.test.ts",
"check:oidc": "mocha --config test/mocha_mongodb.json test/manual/mongodb_oidc.prose.test.ts",
Expand Down
22 changes: 22 additions & 0 deletions test/atlas/drivers_atlas_testing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { writeFile } from 'node:fs/promises';

import * as path from 'path';

import { runUnifiedSuite } from '../tools/unified-spec-runner/runner';

describe('Node Driver Atlas Testing', async function () {
console.log('process.env', process.env);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const spec = JSON.parse(process.env.WORKLOAD_SPECIFICATION!);
runUnifiedSuite([spec]);
// Write the events.json to the execution directory.
await writeFile(
path.join(process.env.OUTPUT_DIRECTORY ?? '', 'events.json'),
JSON.stringify({ events: [], errors: [], failures: [] })
);
// Write the results.json to the execution directory.
await writeFile(
path.join(process.env.OUTPUT_DIRECTORY ?? '', 'results.json'),
JSON.stringify({ numErrors: 0, numFailures: 0, numSuccesses: 0, numIterations: 0 })
);
});
10 changes: 10 additions & 0 deletions test/tools/runner/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ export class TestConfiguration {
}

newClient(dbOptions?: string | Record<string, any>, serverOptions?: Record<string, any>) {
if (process.env.DRIVERS_ATLAS_TESTING_URI) {
console.log('Using drivers Atlas testing URI', process.env.DRIVERS_ATLAS_TESTING_URI);
return new MongoClient(process.env.DRIVERS_ATLAS_TESTING_URI);
}

serverOptions = Object.assign({}, getEnvironmentalOptions(), serverOptions);

// support MongoClient constructor form (url, options) for `newClient`
Expand Down Expand Up @@ -258,6 +263,11 @@ export class TestConfiguration {
...options
};

if (process.env.DRIVERS_ATLAS_TESTING_URI) {
console.log('Using drivers Atlas testing URI', process.env.DRIVERS_ATLAS_TESTING_URI);
return process.env.DRIVERS_ATLAS_TESTING_URI;
}

const FILLER_HOST = 'fillerHost';

const protocol = this.isServerless ? 'mongodb+srv' : 'mongodb';
Expand Down
9 changes: 7 additions & 2 deletions test/tools/unified-spec-runner/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
type ConnectionPoolReadyEvent,
type ConnectionReadyEvent,
Db,
type Document,
Document,
GridFSBucket,
type HostAddress,
type Log,
Expand Down Expand Up @@ -357,6 +357,7 @@ export type Entity =
| AbstractCursor
| UnifiedChangeStream
| GridFSBucket
| Document
| ClientEncryption
| TopologyDescription // From recordTopologyDescription operation
| Document; // Results from operations
Expand All @@ -370,6 +371,7 @@ export type EntityCtor =
| typeof AbstractCursor
| typeof GridFSBucket
| typeof UnifiedThread
| typeof Document
| ClientEncryption;

export type EntityTypeId =
Expand All @@ -381,7 +383,8 @@ export type EntityTypeId =
| 'thread'
| 'cursor'
| 'stream'
| 'clientEncryption';
| 'clientEncryption'
| 'error';

const ENTITY_CTORS = new Map<EntityTypeId, EntityCtor>();
ENTITY_CTORS.set('client', UnifiedMongoClient);
Expand All @@ -392,6 +395,7 @@ ENTITY_CTORS.set('bucket', GridFSBucket);
ENTITY_CTORS.set('thread', UnifiedThread);
ENTITY_CTORS.set('cursor', AbstractCursor);
ENTITY_CTORS.set('stream', ChangeStream);
ENTITY_CTORS.set('error', Document);

export class EntitiesMap<E = Entity> extends Map<string, E> {
failPoints: FailPointMap;
Expand Down Expand Up @@ -435,6 +439,7 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
getEntity(type: 'thread', key: string, assertExists?: boolean): UnifiedThread;
getEntity(type: 'cursor', key: string, assertExists?: boolean): AbstractCursor;
getEntity(type: 'stream', key: string, assertExists?: boolean): UnifiedChangeStream;
getEntity(type: 'error', key: string, assertExists?: boolean): Document[];
getEntity(type: 'clientEncryption', key: string, assertExists?: boolean): ClientEncryption;
getEntity(type: EntityTypeId, key: string, assertExists = true): Entity | undefined {
const entity = this.get(key);
Expand Down
44 changes: 44 additions & 0 deletions test/tools/unified-spec-runner/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,50 @@ operations.set('listIndexes', async ({ entities, operation }) => {
return collection.listIndexes(operation.arguments!).toArray();
});

operations.set('loop', async ({ entities, operation, client, testConfig }) => {
const controller = new AbortController();
process.on('SIGINT', () => {
controller.abort('Process received SIGINT, aborting operation loop.');
});
const args = operation.arguments!;
const storeIterationsAsEntity = args.storeIterationsAsEntity;
const storeSuccessesAsEntity = args.storeSuccessesAsEntity;
const storeErrorsAsEntity = args.storeErrorsAsEntity;
const storeFailuresAsEntity = args.storeFailuresAsEntity;

if (storeErrorsAsEntity) {
entities.set(storeErrorsAsEntity, []);
}
if (storeFailuresAsEntity) {
entities.set(storeFailuresAsEntity, []);
}
let iterations = 0;
let successes = 0;
while (!controller.signal.aborted) {
if (storeIterationsAsEntity) {
entities.set(storeIterationsAsEntity, iterations++);
}
for (const op of args.operations) {
console.log('op', op);
try {
await executeOperationAndCheck(op, entities, client, testConfig);
if (storeSuccessesAsEntity) {
entities.set(storeSuccessesAsEntity, successes++);
}
} catch (error) {
console.log('error', error);
if (storeErrorsAsEntity) {
entities
.getEntity('error', storeErrorsAsEntity)
.push({ error: error.message, time: Date.now() });
} else {
throw error;
}
}
}
}
});

operations.set('replaceOne', async ({ entities, operation }) => {
const collection = entities.getEntity('collection', operation.object);
const { filter, replacement, ...opts } = operation.arguments!;
Expand Down

0 comments on commit 6dbbe8d

Please sign in to comment.