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 4e3a1ba
Show file tree
Hide file tree
Showing 6 changed files with 113 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
8 changes: 8 additions & 0 deletions test/atlas/drivers_atlas_testing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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]);
});
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
23 changes: 21 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,8 +357,10 @@ export type Entity =
| AbstractCursor
| UnifiedChangeStream
| GridFSBucket
| Document
| ClientEncryption
| TopologyDescription // From recordTopologyDescription operation
| number
| Document; // Results from operations

export type EntityCtor =
Expand All @@ -370,6 +372,8 @@ export type EntityCtor =
| typeof AbstractCursor
| typeof GridFSBucket
| typeof UnifiedThread
| typeof Document
| typeof Number
| ClientEncryption;

export type EntityTypeId =
Expand All @@ -381,7 +385,12 @@ export type EntityTypeId =
| 'thread'
| 'cursor'
| 'stream'
| 'clientEncryption';
| 'clientEncryption'
| 'iterations'
| 'successes'
| 'errors'
| 'failures'
| 'events';

const ENTITY_CTORS = new Map<EntityTypeId, EntityCtor>();
ENTITY_CTORS.set('client', UnifiedMongoClient);
Expand All @@ -392,6 +401,11 @@ ENTITY_CTORS.set('bucket', GridFSBucket);
ENTITY_CTORS.set('thread', UnifiedThread);
ENTITY_CTORS.set('cursor', AbstractCursor);
ENTITY_CTORS.set('stream', ChangeStream);
ENTITY_CTORS.set('iterations', Number);
ENTITY_CTORS.set('successes', Number);
ENTITY_CTORS.set('errors', Document);
ENTITY_CTORS.set('failures', Document);
ENTITY_CTORS.set('events', Document);

export class EntitiesMap<E = Entity> extends Map<string, E> {
failPoints: FailPointMap;
Expand Down Expand Up @@ -435,6 +449,11 @@ 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: 'iterations', key: string, assertExists?: boolean): number;
getEntity(type: 'successes', key: string, assertExists?: boolean): number;
getEntity(type: 'errors', key: string, assertExists?: boolean): Document[];
getEntity(type: 'failures', key: string, assertExists?: boolean): Document[];
getEntity(type: 'events', 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
47 changes: 47 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,53 @@ 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('errors', storeErrorsAsEntity)
.push({ error: error.message, time: Date.now() });
}
if (storeFailuresAsEntity) {
entities
.getEntity('failures', storeFailuresAsEntity)
.push({ error: error.message, time: Date.now() });
}
}
}
}
});

operations.set('replaceOne', async ({ entities, operation }) => {
const collection = entities.getEntity('collection', operation.object);
const { filter, replacement, ...opts } = operation.arguments!;
Expand Down
26 changes: 26 additions & 0 deletions test/tools/unified-spec-runner/runner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { writeFile } from 'node:fs/promises';

import { expect } from 'chai';
import * as path from 'path';
import { gte as semverGte, satisfies as semverSatisfies } from 'semver';

import type { MongoClient } from '../../mongodb';
Expand Down Expand Up @@ -255,6 +258,29 @@ async function runUnifiedTest(
}
} finally {
await utilClient.close();
// For astrolabe testing we need to write the entities to files.
if (process.env.WORKLOAD_SPECIFICATION) {
// Write the events.json to the execution directory.
const errors = entities?.getEntity('errors', 'errors');
const failures = entities?.getEntity('failures', 'failures');
const events = entities?.getEntity('events', 'events');
const iterations = entities?.getEntity('iterations', 'events');
const successes = entities?.getEntity('successes', 'events');
await writeFile(
path.join(process.env.OUTPUT_DIRECTORY ?? '', 'events.json'),
JSON.stringify({ events: events, errors: errors, failures: failures })
);
// Write the results.json to the execution directory.
await writeFile(
path.join(process.env.OUTPUT_DIRECTORY ?? '', 'results.json'),
JSON.stringify({
numErrors: errors?.length,
numFailures: failures?.length,
numSuccesses: successes,
numIterations: iterations
})
);
}
await entities?.cleanup();
}
}
Expand Down

0 comments on commit 4e3a1ba

Please sign in to comment.