Skip to content

Commit 533ccea

Browse files
committed
refactor: add mongodb+srv tests to atlas connectivity tests
This simplifies how we test our many connectivity tests while also adding a few new ones for `mongodb+srv` hosts. Specifically, it converts the connectivity tests to a new "manual" style test using mocha, and then merges many environment variables into a single JSON blob. NODE-2021
1 parent c823808 commit 533ccea

File tree

6 files changed

+72
-58
lines changed

6 files changed

+72
-58
lines changed

.evergreen/config.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,23 @@ functions:
154154
- command: shell.exec
155155
type: test
156156
params:
157-
working_dir: src
158157
silent: true
159-
script: >
160-
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
158+
working_dir: src
159+
script: |
160+
cat <<EOT > prepare_atlas_connectivity.sh
161+
export ATLAS_CONNECTIVITY='${ATLAS_CONNECTIVITY}'
162+
EOT
163+
- command: shell.exec
164+
type: test
165+
params:
166+
working_dir: src
167+
script: |
168+
# Disable xtrace (just in case it was accidentally set).
169+
set +x
170+
. ./prepare_atlas_connectivity.sh
171+
rm -f ./prepare_atlas_connectivity.sh
161172
162-
NODE_LTS_NAME='${NODE_LTS_NAME}' ATLAS_REPL='${atlas_repl}' ATLAS_SHRD='${atlas_shrd}'
163-
ATLAS_FREE='${atlas_free}' ATLAS_TLS11='${atlas_tls11}' ATLAS_TLS12='${atlas_tls12}' bash
164-
${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh
173+
NODE_LTS_NAME='${NODE_LTS_NAME}' bash ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh
165174
pre:
166175
- func: fetch source
167176
- func: prepare resources

.evergreen/config.yml.in

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,23 @@ functions:
189189
- command: shell.exec
190190
type: test
191191
params:
192-
working_dir: "src"
193192
silent: true
193+
working_dir: "src"
194194
script: |
195-
# DO NOT ECHO WITH XTRACE (which PREPARE_SHELL does)
196-
NODE_LTS_NAME='${NODE_LTS_NAME}' ATLAS_REPL='${atlas_repl}' ATLAS_SHRD='${atlas_shrd}' ATLAS_FREE='${atlas_free}' ATLAS_TLS11='${atlas_tls11}' ATLAS_TLS12='${atlas_tls12}' bash ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh
195+
cat <<EOT > prepare_atlas_connectivity.sh
196+
export ATLAS_CONNECTIVITY='${ATLAS_CONNECTIVITY}'
197+
EOT
198+
- command: shell.exec
199+
type: test
200+
params:
201+
working_dir: "src"
202+
script: |
203+
# Disable xtrace (just in case it was accidentally set).
204+
set +x
205+
. ./prepare_atlas_connectivity.sh
206+
rm -f ./prepare_atlas_connectivity.sh
207+
208+
NODE_LTS_NAME='${NODE_LTS_NAME}' bash ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh
197209

198210
pre:
199211
- func: "fetch source"

.evergreen/run-atlas-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
77
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
88
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
99

10-
ATLAS_REPL="$ATLAS_REPL" ATLAS_SHRD="$ATLAS_SHRD" ATLAS_FREE="$ATLAS_FREE" ATLAS_TLS11="$ATLAS_TLS11" ATLAS_TLS12="$ATLAS_TLS12" npm run atlas
10+
npm run atlas

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"url": "https://github.com/mongodb/node-mongodb-native/issues"
6565
},
6666
"scripts": {
67-
"atlas": "node ./test/tools/atlas_connectivity_tests.js",
67+
"atlas": "mocha --opts '{}' ./test/manual/atlas_connectivity.test.js",
6868
"test": "npm run lint && mocha --recursive test/functional test/unit test/core",
6969
"test-nolint": "mocha --recursive test/functional test/unit test/core",
7070
"coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/core test/unit test/functional",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
const MongoClient = require('../..').MongoClient;
3+
4+
describe('Atlas Connectivity', function() {
5+
if (process.env.ATLAS_CONNECTIVITY == null) {
6+
console.log(
7+
'skipping atlas connectivity tests, ATLAS_CONNECTIVITY environment variable is not defined'
8+
);
9+
10+
return;
11+
}
12+
13+
const CONFIGS = JSON.parse(process.env.ATLAS_CONNECTIVITY);
14+
Object.keys(CONFIGS).forEach(configName => {
15+
context(configName, function() {
16+
CONFIGS[configName].forEach(connectionString => {
17+
const name = connectionString.indexOf('mongodb+srv') >= 0 ? 'mongodb+srv' : 'normal';
18+
it(`${name} (unified)`, makeConnectionTest(connectionString, { useUnifiedTopology: true }));
19+
it(`${name} (legacy)`, makeConnectionTest(connectionString, { useUnifiedTopology: false }));
20+
});
21+
});
22+
});
23+
});
24+
25+
function makeConnectionTest(connectionString, clientOptions) {
26+
return function() {
27+
const client = new MongoClient(connectionString, clientOptions);
28+
29+
return client
30+
.connect()
31+
.then(() => client.db('admin').command({ ismaster: 1 }))
32+
.then(() =>
33+
client
34+
.db('test')
35+
.collection('test')
36+
.findOne({})
37+
)
38+
.then(() => client.close());
39+
};
40+
}

test/tools/atlas_connectivity_tests.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)