From e2a392bb91f1856f28a0783bd57b7d40af1d258c Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Mon, 17 Jun 2024 10:11:13 -0600 Subject: [PATCH] ci(NODE-6211): fix atlas connectivity tests in 5.x (#4152) --- .evergreen/config.in.yml | 30 ++++++--------- .evergreen/config.yml | 29 ++++++--------- .evergreen/run-atlas-tests.sh | 7 +++- .gitignore | 6 +++ package.json | 2 +- test/manual/atlas_connectivity.test.js | 50 ------------------------- test/manual/atlas_connectivity.test.ts | 51 ++++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 89 deletions(-) delete mode 100644 test/manual/atlas_connectivity.test.js create mode 100644 test/manual/atlas_connectivity.test.ts diff --git a/.evergreen/config.in.yml b/.evergreen/config.in.yml index 4e64b0ca93..a6a223aa32 100644 --- a/.evergreen/config.in.yml +++ b/.evergreen/config.in.yml @@ -434,29 +434,23 @@ functions: rm -rf ./node_modules/@aws-sdk/credential-providers "run atlas tests": - - command: shell.exec - type: test + # This creates secrets-export.sh, which is later sourced by run-tests.sh + - command: subprocess.exec params: - silent: true working_dir: "src" - script: | - cat < prepare_atlas_connectivity.sh - export ATLAS_CONNECTIVITY='${ATLAS_CONNECTIVITY}' - EOT - - command: shell.exec + binary: bash + args: + - -c + - ${DRIVERS_TOOLS}/.evergreen/secrets_handling/setup-secrets.sh drivers/atlas_connect + - command: subprocess.exec type: test params: working_dir: "src" - script: | - # Disable xtrace (just in case it was accidentally set). - set +x - . ./prepare_atlas_connectivity.sh - rm -f ./prepare_atlas_connectivity.sh - - export PROJECT_DIRECTORY="$(pwd)" - export NODE_LTS_VERSION='${NODE_LTS_VERSION}' - - bash ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh + binary: bash + env: + NODE_LTS_VERSION: ${NODE_LTS_VERSION} + args: + - .evergreen/run-atlas-tests.sh "run socks5 tests": - command: shell.exec diff --git a/.evergreen/config.yml b/.evergreen/config.yml index e3d32802c4..35cde37fd7 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -389,29 +389,22 @@ functions: source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" rm -rf ./node_modules/@aws-sdk/credential-providers run atlas tests: - - command: shell.exec - type: test + - command: subprocess.exec params: - silent: true working_dir: src - script: | - cat < prepare_atlas_connectivity.sh - export ATLAS_CONNECTIVITY='${ATLAS_CONNECTIVITY}' - EOT - - command: shell.exec + binary: bash + args: + - '-c' + - ${DRIVERS_TOOLS}/.evergreen/secrets_handling/setup-secrets.sh drivers/atlas_connect + - command: subprocess.exec type: test params: working_dir: src - script: | - # Disable xtrace (just in case it was accidentally set). - set +x - . ./prepare_atlas_connectivity.sh - rm -f ./prepare_atlas_connectivity.sh - - export PROJECT_DIRECTORY="$(pwd)" - export NODE_LTS_VERSION='${NODE_LTS_VERSION}' - - bash ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh + binary: bash + env: + NODE_LTS_VERSION: ${NODE_LTS_VERSION} + args: + - .evergreen/run-atlas-tests.sh run socks5 tests: - command: shell.exec type: test diff --git a/.evergreen/run-atlas-tests.sh b/.evergreen/run-atlas-tests.sh index c65b8512a7..694cefaf43 100644 --- a/.evergreen/run-atlas-tests.sh +++ b/.evergreen/run-atlas-tests.sh @@ -2,9 +2,12 @@ set -o errexit # Exit the script with error if any of the commands fail -source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" +if test -f secrets-export.sh; then + source secrets-export.sh +fi -set -o xtrace +PROJECT_DIRECTORY=${PROJECT_DIRECTORY:-"."} +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" node -v diff --git a/.gitignore b/.gitignore index 7a71ba0b97..e1c70e581c 100644 --- a/.gitignore +++ b/.gitignore @@ -99,3 +99,9 @@ test/lambda/env.json !encryption/lib !encryption/test !encryption/test/types + +# files generated by tooling in drivers-evergreen-tools +secrets-export.sh +mo-expansion.sh +mo-expansion.yml +expansions.sh diff --git a/package.json b/package.json index 451b6f9489..6e617f1dc9 100644 --- a/package.json +++ b/package.json @@ -133,7 +133,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: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", diff --git a/test/manual/atlas_connectivity.test.js b/test/manual/atlas_connectivity.test.js deleted file mode 100644 index 928e8ad3fb..0000000000 --- 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 0000000000..a49ed0bafc --- /dev/null +++ b/test/manual/atlas_connectivity.test.ts @@ -0,0 +1,51 @@ +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 () { + let client: MongoClient; + + afterEach(async function () { + await client?.close(); + }); + + const environments = [ + 'ATLAS_SERVERLESS', + 'ATLAS_SRV_SERVERLESS', + 'ATLAS_FREE', + 'ATLAS_SRV_FREE', + 'ATLAS_REPL', + 'ATLAS_SRV_REPL', + 'ATLAS_SHRD', + 'ATLAS_SRV_SHRD', + 'ATLAS_TLS11', + 'ATLAS_SRV_TLS11', + 'ATLAS_TLS12', + 'ATLAS_SRV_TLS12' + ]; + + for (const environment of environments) { + it(`${environment} connects successfully`, async function () { + this.timeout(40000); + + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + client = new MongoClient(process.env[environment]!); + + await client.connect(); + await client.db('admin').command({ [LEGACY_HELLO_COMMAND]: 1 }); + await client.db('test').collection('test').findOne({}); + }); + } +});