Skip to content

Commit 6dbbe8d

Browse files
committed
test(NODE-3049): drivers atlas testing
1 parent a17b0af commit 6dbbe8d

File tree

5 files changed

+84
-2
lines changed

5 files changed

+84
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
"check:unit": "mocha test/unit",
144144
"check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",
145145
"check:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.js",
146+
"check:drivers-atlas-testing": "mocha --config test/mocha_mongodb.json test/atlas/drivers_atlas_testing.test.ts",
146147
"check:adl": "mocha --config test/mocha_mongodb.json test/manual/atlas-data-lake-testing",
147148
"check:aws": "nyc mocha --config test/mocha_mongodb.json test/integration/auth/mongodb_aws.test.ts",
148149
"check:oidc": "mocha --config test/mocha_mongodb.json test/manual/mongodb_oidc.prose.test.ts",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { writeFile } from 'node:fs/promises';
2+
3+
import * as path from 'path';
4+
5+
import { runUnifiedSuite } from '../tools/unified-spec-runner/runner';
6+
7+
describe('Node Driver Atlas Testing', async function () {
8+
console.log('process.env', process.env);
9+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
10+
const spec = JSON.parse(process.env.WORKLOAD_SPECIFICATION!);
11+
runUnifiedSuite([spec]);
12+
// Write the events.json to the execution directory.
13+
await writeFile(
14+
path.join(process.env.OUTPUT_DIRECTORY ?? '', 'events.json'),
15+
JSON.stringify({ events: [], errors: [], failures: [] })
16+
);
17+
// Write the results.json to the execution directory.
18+
await writeFile(
19+
path.join(process.env.OUTPUT_DIRECTORY ?? '', 'results.json'),
20+
JSON.stringify({ numErrors: 0, numFailures: 0, numSuccesses: 0, numIterations: 0 })
21+
);
22+
});

test/tools/runner/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ export class TestConfiguration {
159159
}
160160

161161
newClient(dbOptions?: string | Record<string, any>, serverOptions?: Record<string, any>) {
162+
if (process.env.DRIVERS_ATLAS_TESTING_URI) {
163+
console.log('Using drivers Atlas testing URI', process.env.DRIVERS_ATLAS_TESTING_URI);
164+
return new MongoClient(process.env.DRIVERS_ATLAS_TESTING_URI);
165+
}
166+
162167
serverOptions = Object.assign({}, getEnvironmentalOptions(), serverOptions);
163168

164169
// support MongoClient constructor form (url, options) for `newClient`
@@ -258,6 +263,11 @@ export class TestConfiguration {
258263
...options
259264
};
260265

266+
if (process.env.DRIVERS_ATLAS_TESTING_URI) {
267+
console.log('Using drivers Atlas testing URI', process.env.DRIVERS_ATLAS_TESTING_URI);
268+
return process.env.DRIVERS_ATLAS_TESTING_URI;
269+
}
270+
261271
const FILLER_HOST = 'fillerHost';
262272

263273
const protocol = this.isServerless ? 'mongodb+srv' : 'mongodb';

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
type ConnectionPoolReadyEvent,
2323
type ConnectionReadyEvent,
2424
Db,
25-
type Document,
25+
Document,
2626
GridFSBucket,
2727
type HostAddress,
2828
type Log,
@@ -357,6 +357,7 @@ export type Entity =
357357
| AbstractCursor
358358
| UnifiedChangeStream
359359
| GridFSBucket
360+
| Document
360361
| ClientEncryption
361362
| TopologyDescription // From recordTopologyDescription operation
362363
| Document; // Results from operations
@@ -370,6 +371,7 @@ export type EntityCtor =
370371
| typeof AbstractCursor
371372
| typeof GridFSBucket
372373
| typeof UnifiedThread
374+
| typeof Document
373375
| ClientEncryption;
374376

375377
export type EntityTypeId =
@@ -381,7 +383,8 @@ export type EntityTypeId =
381383
| 'thread'
382384
| 'cursor'
383385
| 'stream'
384-
| 'clientEncryption';
386+
| 'clientEncryption'
387+
| 'error';
385388

386389
const ENTITY_CTORS = new Map<EntityTypeId, EntityCtor>();
387390
ENTITY_CTORS.set('client', UnifiedMongoClient);
@@ -392,6 +395,7 @@ ENTITY_CTORS.set('bucket', GridFSBucket);
392395
ENTITY_CTORS.set('thread', UnifiedThread);
393396
ENTITY_CTORS.set('cursor', AbstractCursor);
394397
ENTITY_CTORS.set('stream', ChangeStream);
398+
ENTITY_CTORS.set('error', Document);
395399

396400
export class EntitiesMap<E = Entity> extends Map<string, E> {
397401
failPoints: FailPointMap;
@@ -435,6 +439,7 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
435439
getEntity(type: 'thread', key: string, assertExists?: boolean): UnifiedThread;
436440
getEntity(type: 'cursor', key: string, assertExists?: boolean): AbstractCursor;
437441
getEntity(type: 'stream', key: string, assertExists?: boolean): UnifiedChangeStream;
442+
getEntity(type: 'error', key: string, assertExists?: boolean): Document[];
438443
getEntity(type: 'clientEncryption', key: string, assertExists?: boolean): ClientEncryption;
439444
getEntity(type: EntityTypeId, key: string, assertExists = true): Entity | undefined {
440445
const entity = this.get(key);

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,50 @@ operations.set('listIndexes', async ({ entities, operation }) => {
377377
return collection.listIndexes(operation.arguments!).toArray();
378378
});
379379

380+
operations.set('loop', async ({ entities, operation, client, testConfig }) => {
381+
const controller = new AbortController();
382+
process.on('SIGINT', () => {
383+
controller.abort('Process received SIGINT, aborting operation loop.');
384+
});
385+
const args = operation.arguments!;
386+
const storeIterationsAsEntity = args.storeIterationsAsEntity;
387+
const storeSuccessesAsEntity = args.storeSuccessesAsEntity;
388+
const storeErrorsAsEntity = args.storeErrorsAsEntity;
389+
const storeFailuresAsEntity = args.storeFailuresAsEntity;
390+
391+
if (storeErrorsAsEntity) {
392+
entities.set(storeErrorsAsEntity, []);
393+
}
394+
if (storeFailuresAsEntity) {
395+
entities.set(storeFailuresAsEntity, []);
396+
}
397+
let iterations = 0;
398+
let successes = 0;
399+
while (!controller.signal.aborted) {
400+
if (storeIterationsAsEntity) {
401+
entities.set(storeIterationsAsEntity, iterations++);
402+
}
403+
for (const op of args.operations) {
404+
console.log('op', op);
405+
try {
406+
await executeOperationAndCheck(op, entities, client, testConfig);
407+
if (storeSuccessesAsEntity) {
408+
entities.set(storeSuccessesAsEntity, successes++);
409+
}
410+
} catch (error) {
411+
console.log('error', error);
412+
if (storeErrorsAsEntity) {
413+
entities
414+
.getEntity('error', storeErrorsAsEntity)
415+
.push({ error: error.message, time: Date.now() });
416+
} else {
417+
throw error;
418+
}
419+
}
420+
}
421+
}
422+
});
423+
380424
operations.set('replaceOne', async ({ entities, operation }) => {
381425
const collection = entities.getEntity('collection', operation.object);
382426
const { filter, replacement, ...opts } = operation.arguments!;

0 commit comments

Comments
 (0)