From 0209cfe68217b45ca0c1503bd9fe234de3a0dd27 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Fri, 15 Mar 2024 12:21:19 -0400 Subject: [PATCH 1/2] test(NODE-6028): skip atlas connectivity free tier 4.4 --- package.json | 2 +- test/manual/atlas_connectivity.test.js | 50 ------------------- test/manual/atlas_connectivity.test.ts | 67 ++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 51 deletions(-) delete mode 100644 test/manual/atlas_connectivity.test.js create mode 100644 test/manual/atlas_connectivity.test.ts diff --git a/package.json b/package.json index e9da4bc0869..f38b91971f4 100644 --- a/package.json +++ b/package.json @@ -143,7 +143,7 @@ "check:test": "mocha --config test/mocha_mongodb.json test/integration", "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:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.ts", "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", diff --git a/test/manual/atlas_connectivity.test.js b/test/manual/atlas_connectivity.test.js deleted file mode 100644 index 928e8ad3fbb..00000000000 --- a/test/manual/atlas_connectivity.test.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict'; -const { MongoClient } = require('../mongodb'); -const { LEGACY_HELLO_COMMAND } = require('../mongodb'); - -/** - * ATLAS_CONNECTIVITY env variable is JSON - * Here's some typescript describing the shape: - * - * ```typescript - * interface AtlasConnectivity { - * [atlasDeployment: string]: [normalUri: string, srvUri: string] - * } - * ``` - * - * It should be an object with descriptive strings about the deployment type and version (i.e. sharded_cluster_3_4) - * that map to a two string tuple that are the normal URI and SRV URI, order doesn't matter, but it should be that order. - */ - -describe('Atlas Connectivity', function () { - if (process.env.ATLAS_CONNECTIVITY == null) { - console.error( - 'skipping atlas connectivity tests, ATLAS_CONNECTIVITY environment variable is not defined' - ); - - return; - } - - const CONFIGS = JSON.parse(process.env.ATLAS_CONNECTIVITY); - Object.keys(CONFIGS).forEach(configName => { - context(configName, function () { - CONFIGS[configName].forEach(connectionString => { - const name = connectionString.indexOf('mongodb+srv') >= 0 ? 'mongodb+srv' : 'normal'; - it(`${name}`, makeConnectionTest(connectionString)); - }); - }); - }); -}); - -function makeConnectionTest(connectionString, clientOptions) { - return function () { - this.timeout(40000); - const client = new MongoClient(connectionString, clientOptions); - - return client - .connect() - .then(() => client.db('admin').command({ [LEGACY_HELLO_COMMAND]: 1 })) - .then(() => client.db('test').collection('test').findOne({})) - .then(() => client.close()); - }; -} diff --git a/test/manual/atlas_connectivity.test.ts b/test/manual/atlas_connectivity.test.ts new file mode 100644 index 00000000000..9cf1a11601a --- /dev/null +++ b/test/manual/atlas_connectivity.test.ts @@ -0,0 +1,67 @@ +import { LEGACY_HELLO_COMMAND, MongoClient } from '../mongodb'; + +/** + * ATLAS_CONNECTIVITY env variable is JSON + * Here's some typescript describing the shape: + * + * ```typescript + * interface AtlasConnectivity { + * [atlasDeployment: string]: [normalUri: string, srvUri: string] + * } + * ``` + * + * It should be an object with descriptive strings about the deployment type and version (i.e. sharded_cluster_3_4) + * that map to a two string tuple that are the normal URI and SRV URI, order doesn't matter, but it should be that order. + */ + +describe('Atlas Connectivity', function () { + if (process.env.ATLAS_CONNECTIVITY == null) { + console.error( + 'skipping atlas connectivity tests, ATLAS_CONNECTIVITY environment variable is not defined' + ); + + return; + } + + const CONFIGS: Record = JSON.parse( + process.env.ATLAS_CONNECTIVITY + ); + + let client; + + afterEach(async function () { + await client.close(); + }); + + for (const configName of Object.keys(CONFIGS)) { + context(configName, function () { + for (const connectionString of CONFIGS[configName]) { + const name = connectionString.includes('mongodb+srv') ? 'mongodb+srv' : 'normal'; + + beforeEach(function () { + if (configName === 'replica_set_4_4_free') { + const today = new Date(); + // Making this April 1st so it is a monday + const april1st2024 = new Date('2024-04-01'); + if (today < april1st2024) { + if (this.currentTest) + this.currentTest.skipReason = + 'TODO(NODE-6027): Un-skip replica_set_4_4_free after March 29th 2024'; + this.skip(); + } + } + }); + + it(name, async function () { + this.timeout(40000); + + client = new MongoClient(connectionString); + + await client.connect(); + await client.db('admin').command({ [LEGACY_HELLO_COMMAND]: 1 }); + await client.db('test').collection('test').findOne({}); + }); + } + }); + } +}); From 5f2e27919f1d5d6b5295dee55bfd4c3020312677 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 18 Mar 2024 12:41:55 -0400 Subject: [PATCH 2/2] test: prevent accidental skip --- test/manual/atlas_connectivity.test.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/test/manual/atlas_connectivity.test.ts b/test/manual/atlas_connectivity.test.ts index 9cf1a11601a..dc55bbe7930 100644 --- a/test/manual/atlas_connectivity.test.ts +++ b/test/manual/atlas_connectivity.test.ts @@ -15,19 +15,13 @@ import { LEGACY_HELLO_COMMAND, MongoClient } from '../mongodb'; */ describe('Atlas Connectivity', function () { - if (process.env.ATLAS_CONNECTIVITY == null) { - console.error( - 'skipping atlas connectivity tests, ATLAS_CONNECTIVITY environment variable is not defined' - ); + const { ATLAS_CONNECTIVITY = '' } = process.env; + if (ATLAS_CONNECTIVITY === '') throw new Error('ATLAS_CONNECTIVITY not defined in env'); - return; - } - - const CONFIGS: Record = JSON.parse( - process.env.ATLAS_CONNECTIVITY - ); + const CONFIGS: Record = + JSON.parse(ATLAS_CONNECTIVITY); - let client; + let client: MongoClient; afterEach(async function () { await client.close();