Skip to content

Commit

Permalink
ci(NODE-6203): fix atlas connectivity tests (#4142)
Browse files Browse the repository at this point in the history
Co-authored-by: Durran Jordan <durran@gmail.com>
  • Loading branch information
baileympearson and durran authored Jun 13, 2024
1 parent 35fd6b0 commit 0c687a5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 74 deletions.
30 changes: 12 additions & 18 deletions .evergreen/config.in.yml
Original file line number Diff line number Diff line change
Expand Up @@ -440,29 +440,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 <<EOT > 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
Expand Down
29 changes: 11 additions & 18 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -395,29 +395,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 <<EOT > 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
Expand Down
7 changes: 5 additions & 2 deletions .evergreen/run-atlas-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
62 changes: 26 additions & 36 deletions test/manual/atlas_connectivity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,37 @@ import { LEGACY_HELLO_COMMAND, MongoClient } from '../mongodb';
*/

describe('Atlas Connectivity', function () {
const { ATLAS_CONNECTIVITY = '' } = process.env;
if (ATLAS_CONNECTIVITY === '') throw new Error('ATLAS_CONNECTIVITY not defined in env');

const CONFIGS: Record<string, [normalUri: string, srvUri: string]> =
JSON.parse(ATLAS_CONNECTIVITY);

let client: MongoClient;

afterEach(async function () {
await client.close();
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({});
});
}
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({});
});
}
});

0 comments on commit 0c687a5

Please sign in to comment.