Skip to content

Commit 0c687a5

Browse files
ci(NODE-6203): fix atlas connectivity tests (#4142)
Co-authored-by: Durran Jordan <[email protected]>
1 parent 35fd6b0 commit 0c687a5

File tree

4 files changed

+54
-74
lines changed

4 files changed

+54
-74
lines changed

.evergreen/config.in.yml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -440,29 +440,23 @@ functions:
440440
rm -rf ./node_modules/@aws-sdk/credential-providers
441441
442442
"run atlas tests":
443-
- command: shell.exec
444-
type: test
443+
# This creates secrets-export.sh, which is later sourced by run-tests.sh
444+
- command: subprocess.exec
445445
params:
446-
silent: true
447446
working_dir: "src"
448-
script: |
449-
cat <<EOT > prepare_atlas_connectivity.sh
450-
export ATLAS_CONNECTIVITY='${ATLAS_CONNECTIVITY}'
451-
EOT
452-
- command: shell.exec
447+
binary: bash
448+
args:
449+
- -c
450+
- ${DRIVERS_TOOLS}/.evergreen/secrets_handling/setup-secrets.sh drivers/atlas_connect
451+
- command: subprocess.exec
453452
type: test
454453
params:
455454
working_dir: "src"
456-
script: |
457-
# Disable xtrace (just in case it was accidentally set).
458-
set +x
459-
. ./prepare_atlas_connectivity.sh
460-
rm -f ./prepare_atlas_connectivity.sh
461-
462-
export PROJECT_DIRECTORY="$(pwd)"
463-
export NODE_LTS_VERSION='${NODE_LTS_VERSION}'
464-
465-
bash ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh
455+
binary: bash
456+
env:
457+
NODE_LTS_VERSION: ${NODE_LTS_VERSION}
458+
args:
459+
- .evergreen/run-atlas-tests.sh
466460

467461
"run socks5 tests":
468462
- command: shell.exec

.evergreen/config.yml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -395,29 +395,22 @@ functions:
395395
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
396396
rm -rf ./node_modules/@aws-sdk/credential-providers
397397
run atlas tests:
398-
- command: shell.exec
399-
type: test
398+
- command: subprocess.exec
400399
params:
401-
silent: true
402400
working_dir: src
403-
script: |
404-
cat <<EOT > prepare_atlas_connectivity.sh
405-
export ATLAS_CONNECTIVITY='${ATLAS_CONNECTIVITY}'
406-
EOT
407-
- command: shell.exec
401+
binary: bash
402+
args:
403+
- '-c'
404+
- ${DRIVERS_TOOLS}/.evergreen/secrets_handling/setup-secrets.sh drivers/atlas_connect
405+
- command: subprocess.exec
408406
type: test
409407
params:
410408
working_dir: src
411-
script: |
412-
# Disable xtrace (just in case it was accidentally set).
413-
set +x
414-
. ./prepare_atlas_connectivity.sh
415-
rm -f ./prepare_atlas_connectivity.sh
416-
417-
export PROJECT_DIRECTORY="$(pwd)"
418-
export NODE_LTS_VERSION='${NODE_LTS_VERSION}'
419-
420-
bash ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh
409+
binary: bash
410+
env:
411+
NODE_LTS_VERSION: ${NODE_LTS_VERSION}
412+
args:
413+
- .evergreen/run-atlas-tests.sh
421414
run socks5 tests:
422415
- command: shell.exec
423416
type: test

.evergreen/run-atlas-tests.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
set -o errexit # Exit the script with error if any of the commands fail
44

5-
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
5+
if test -f secrets-export.sh; then
6+
source secrets-export.sh
7+
fi
68

7-
set -o xtrace
9+
PROJECT_DIRECTORY=${PROJECT_DIRECTORY:-"."}
10+
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
811

912
node -v
1013

test/manual/atlas_connectivity.test.ts

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,37 @@ import { LEGACY_HELLO_COMMAND, MongoClient } from '../mongodb';
1515
*/
1616

1717
describe('Atlas Connectivity', function () {
18-
const { ATLAS_CONNECTIVITY = '' } = process.env;
19-
if (ATLAS_CONNECTIVITY === '') throw new Error('ATLAS_CONNECTIVITY not defined in env');
20-
21-
const CONFIGS: Record<string, [normalUri: string, srvUri: string]> =
22-
JSON.parse(ATLAS_CONNECTIVITY);
23-
2418
let client: MongoClient;
2519

2620
afterEach(async function () {
27-
await client.close();
21+
await client?.close();
2822
});
2923

30-
for (const configName of Object.keys(CONFIGS)) {
31-
context(configName, function () {
32-
for (const connectionString of CONFIGS[configName]) {
33-
const name = connectionString.includes('mongodb+srv') ? 'mongodb+srv' : 'normal';
34-
35-
beforeEach(function () {
36-
if (configName === 'replica_set_4_4_free') {
37-
const today = new Date();
38-
// Making this April 1st so it is a monday
39-
const april1st2024 = new Date('2024-04-01');
40-
if (today < april1st2024) {
41-
if (this.currentTest)
42-
this.currentTest.skipReason =
43-
'TODO(NODE-6027): Un-skip replica_set_4_4_free after March 29th 2024';
44-
this.skip();
45-
}
46-
}
47-
});
48-
49-
it(name, async function () {
50-
this.timeout(40000);
51-
52-
client = new MongoClient(connectionString);
53-
54-
await client.connect();
55-
await client.db('admin').command({ [LEGACY_HELLO_COMMAND]: 1 });
56-
await client.db('test').collection('test').findOne({});
57-
});
58-
}
24+
const environments = [
25+
'ATLAS_SERVERLESS',
26+
'ATLAS_SRV_SERVERLESS',
27+
'ATLAS_FREE',
28+
'ATLAS_SRV_FREE',
29+
'ATLAS_REPL',
30+
'ATLAS_SRV_REPL',
31+
'ATLAS_SHRD',
32+
'ATLAS_SRV_SHRD',
33+
'ATLAS_TLS11',
34+
'ATLAS_SRV_TLS11',
35+
'ATLAS_TLS12',
36+
'ATLAS_SRV_TLS12'
37+
];
38+
39+
for (const environment of environments) {
40+
it(`${environment} connects successfully`, async function () {
41+
this.timeout(40000);
42+
43+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
44+
client = new MongoClient(process.env[environment]!);
45+
46+
await client.connect();
47+
await client.db('admin').command({ [LEGACY_HELLO_COMMAND]: 1 });
48+
await client.db('test').collection('test').findOne({});
5949
});
6050
}
6151
});

0 commit comments

Comments
 (0)