Skip to content

Commit b93300f

Browse files
authored
test(NODE-3072): serverless testing (#2905)
1 parent 2cdbc08 commit b93300f

File tree

16 files changed

+369
-81
lines changed

16 files changed

+369
-81
lines changed

.evergreen/config.yml

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ functions:
134134
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
135135
NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} NO_EXIT=${NO_EXIT|1} \
136136
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
137+
run serverless tests:
138+
- command: timeout.update
139+
params:
140+
exec_timeout_secs: 1800
141+
- command: shell.exec
142+
type: test
143+
params:
144+
working_dir: src
145+
script: |
146+
${PREPARE_SHELL}
147+
# Disable xtrace (just in case it was accidentally set).
148+
set +x
149+
MONGODB_URI="${MONGODB_URI}" \
150+
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
151+
AUTH="auth" SSL="ssl" SERVERLESS=1 \
152+
SERVERLESS_ATLAS_USER="${SERVERLESS_ATLAS_USER}" \
153+
SERVERLESS_ATLAS_PASSWORD="${SERVERLESS_ATLAS_PASSWORD}" \
154+
bash ${PROJECT_DIRECTORY}/.evergreen/run-serverless-tests.sh
137155
start-load-balancer:
138156
- command: shell.exec
139157
params:
@@ -605,18 +623,12 @@ functions:
605623
- command: attach.xunit_results
606624
params:
607625
file: src/xunit.xml
608-
pre:
609-
- func: fetch source
610-
- func: prepare resources
611-
- func: windows fix
612-
- func: fix absolute paths
613-
- func: make files executable
614-
post:
615-
- func: upload test results
616-
- func: cleanup
617-
ignore:
618-
- '*.md'
619626
tasks:
627+
- name: test-serverless
628+
tags:
629+
- serverless
630+
commands:
631+
- func: run serverless tests
620632
- name: test-latest-server
621633
tags:
622634
- latest
@@ -1689,6 +1701,51 @@ tasks:
16891701
- func: run bson-ext test
16901702
vars:
16911703
NODE_LTS_NAME: erbium
1704+
task_groups:
1705+
- name: serverless_task_group
1706+
setup_group_can_fail_task: true
1707+
setup_group_timeout_secs: 1800
1708+
setup_group:
1709+
- func: fetch source
1710+
- func: prepare resources
1711+
- command: shell.exec
1712+
params:
1713+
shell: bash
1714+
script: |
1715+
${PREPARE_SHELL}
1716+
set +o xtrace
1717+
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
1718+
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
1719+
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
1720+
bash ${DRIVERS_TOOLS}/.evergreen/serverless/create-instance.sh
1721+
- command: expansions.update
1722+
params:
1723+
file: serverless-expansion.yml
1724+
teardown_group:
1725+
- func: upload test results
1726+
- command: shell.exec
1727+
params:
1728+
script: |
1729+
${PREPARE_SHELL}
1730+
set +o xtrace
1731+
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
1732+
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
1733+
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
1734+
SERVERLESS_INSTANCE_NAME=${SERVERLESS_INSTANCE_NAME} \
1735+
bash ${DRIVERS_TOOLS}/.evergreen/serverless/delete-instance.sh
1736+
tasks:
1737+
- .serverless
1738+
pre:
1739+
- func: fetch source
1740+
- func: prepare resources
1741+
- func: windows fix
1742+
- func: fix absolute paths
1743+
- func: make files executable
1744+
post:
1745+
- func: upload test results
1746+
- func: cleanup
1747+
ignore:
1748+
- '*.md'
16921749
buildvariants:
16931750
- name: macos-1014-erbium
16941751
display_name: macOS 10.14 Node Erbium
@@ -1975,3 +2032,10 @@ buildvariants:
19752032
- aws-4.4-auth-test-run-aws-auth-test-with-aws-credentials-as-environment-variables
19762033
- aws-4.4-auth-test-run-aws-auth-test-with-aws-credentials-and-session-token-as-environment-variables
19772034
- aws-4.4-auth-test-run-aws-ECS-auth-test
2035+
- name: ubuntu1804-test-serverless
2036+
display_name: Serverless Test
2037+
run_on: ubuntu1804-test
2038+
expansions:
2039+
NODE_LTS_NAME: erbium
2040+
tasks:
2041+
- serverless_task_group

.evergreen/config.yml.in

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,25 @@ functions:
155155
NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} NO_EXIT=${NO_EXIT|1} \
156156
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
157157

158+
"run serverless tests":
159+
- command: timeout.update
160+
params:
161+
exec_timeout_secs: 1800
162+
- command: shell.exec
163+
type: test
164+
params:
165+
working_dir: "src"
166+
script: |
167+
${PREPARE_SHELL}
168+
# Disable xtrace (just in case it was accidentally set).
169+
set +x
170+
MONGODB_URI="${MONGODB_URI}" \
171+
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
172+
AUTH="auth" SSL="ssl" SERVERLESS=1 \
173+
SERVERLESS_ATLAS_USER="${SERVERLESS_ATLAS_USER}" \
174+
SERVERLESS_ATLAS_PASSWORD="${SERVERLESS_ATLAS_PASSWORD}" \
175+
bash ${PROJECT_DIRECTORY}/.evergreen/run-serverless-tests.sh
176+
158177
"start-load-balancer":
159178
- command: shell.exec
160179
params:
@@ -648,6 +667,47 @@ functions:
648667
params:
649668
file: "src/xunit.xml"
650669

670+
tasks:
671+
- name: "test-serverless"
672+
tags: ["serverless"]
673+
commands:
674+
- func: "run serverless tests"
675+
676+
task_groups:
677+
- name: serverless_task_group
678+
setup_group_can_fail_task: true
679+
setup_group_timeout_secs: 1800 # 30 minutes
680+
setup_group:
681+
- func: "fetch source"
682+
- func: "prepare resources"
683+
- command: shell.exec
684+
params:
685+
shell: "bash"
686+
script: |
687+
${PREPARE_SHELL}
688+
set +o xtrace
689+
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
690+
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
691+
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
692+
bash ${DRIVERS_TOOLS}/.evergreen/serverless/create-instance.sh
693+
- command: expansions.update
694+
params:
695+
file: serverless-expansion.yml
696+
teardown_group:
697+
- func: "upload test results"
698+
- command: shell.exec
699+
params:
700+
script: |
701+
${PREPARE_SHELL}
702+
set +o xtrace
703+
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
704+
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
705+
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
706+
SERVERLESS_INSTANCE_NAME=${SERVERLESS_INSTANCE_NAME} \
707+
bash ${DRIVERS_TOOLS}/.evergreen/serverless/delete-instance.sh
708+
tasks:
709+
- ".serverless"
710+
651711
pre:
652712
- func: "fetch source"
653713
- func: "prepare resources"

.evergreen/generate_evergreen_tasks.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,17 @@ SINGLETON_TASKS.push({
626626
]
627627
});
628628

629+
// special case for serverless testing
630+
BUILD_VARIANTS.push({
631+
name: 'ubuntu1804-test-serverless',
632+
display_name: 'Serverless Test',
633+
run_on: 'ubuntu1804-test',
634+
expansions: {
635+
NODE_LTS_NAME: LOWEST_LTS
636+
},
637+
tasks: ['serverless_task_group']
638+
});
639+
629640
const fileData = yaml.safeLoad(fs.readFileSync(`${__dirname}/config.yml.in`, 'utf8'));
630641
fileData.tasks = (fileData.tasks || []).concat(BASE_TASKS).concat(TASKS).concat(SINGLETON_TASKS);
631642
fileData.buildvariants = (fileData.buildvariants || []).concat(BUILD_VARIANTS);

.evergreen/run-serverless-tests.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
source "${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh"
3+
4+
SERVERLESS_ATLAS_USER="${SERVERLESS_ATLAS_USER}" \
5+
SERVERLESS_ATLAS_PASSWORD="${SERVERLESS_ATLAS_PASSWORD}" \
6+
SERVERLESS=1 AUTH=auth SSL=ssl \
7+
MONGODB_URI=${MONGODB_URI} npx mocha \
8+
test/functional/crud_spec.test.js \
9+
test/functional/retryable_reads.test.js \
10+
test/functional/retryable_writes.test.js \
11+
test/functional/sessions.test.js \
12+
test/functional/transactions.test.js \
13+
test/functional/versioned-api.test.js

test/functional/crud_spec.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ function enforceServerVersionLimits(requires, scenario) {
2020
if (versionLimits.length) {
2121
requires.mongodb = versionLimits.join(' ');
2222
}
23+
if (scenario.serverless) {
24+
requires.serverless = scenario.serverless;
25+
}
2326
}
2427

2528
function findScenarios() {
@@ -35,7 +38,7 @@ const readScenarios = findScenarios('v1', 'read');
3538
const writeScenarios = findScenarios('v1', 'write');
3639

3740
const testContext = {};
38-
describe('CRUD spec', function () {
41+
describe('CRUD spec v1', function () {
3942
beforeEach(function () {
4043
const configuration = this.configuration;
4144
const client = configuration.newClient();

test/functional/sessions.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ describe('Sessions', function () {
6666
});
6767

6868
describe('withSession', {
69-
metadata: { requires: { mongodb: '>=3.6.0' } },
69+
metadata: {
70+
requires: {
71+
mongodb: '>=3.6.0'
72+
}
73+
},
7074
test: function () {
7175
beforeEach(function () {
7276
return test.setup(this.configuration);

test/functional/spec-runner/context.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ class TestRunnerContext {
4444
this.user = opts.user;
4545
this.password = opts.password;
4646
this.authSource = opts.authSource;
47+
if (process.env.SERVERLESS) {
48+
this.user = process.env.SERVERLESS_ATLAS_USER;
49+
this.password = process.env.SERVERLESS_ATLAS_PASSWORD;
50+
this.authSource = 'admin';
51+
this.serverless = true;
52+
}
4753
this.sharedClient = null;
4854
this.failPointClients = [];
4955
this.appliedFailPoints = [];

test/functional/spec-runner/index.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { EJSON } = require('bson');
77
const { isRecord } = require('../../../src/utils');
88
const TestRunnerContext = require('./context').TestRunnerContext;
99
const resolveConnectionString = require('./utils').resolveConnectionString;
10+
const { shouldRunServerlessTest } = require('../../tools/utils');
1011

1112
// Promise.try alternative https://stackoverflow.com/questions/60624081/promise-try-without-bluebird/60624164?noredirect=1#comment107255389_60624164
1213
function promiseTry(callback) {
@@ -110,7 +111,12 @@ function parseRunOn(runOn) {
110111
}
111112

112113
const mongodb = version.join(' ');
113-
return { topology, mongodb, authEnabled: !!config.authEnabled };
114+
return {
115+
topology,
116+
mongodb,
117+
authEnabled: !!config.authEnabled,
118+
serverless: config.serverless
119+
};
114120
});
115121
}
116122

@@ -167,6 +173,13 @@ function shouldRunSpecTest(configuration, requires, spec, filter) {
167173
return false;
168174
}
169175

176+
if (
177+
requires.serverless &&
178+
!shouldRunServerlessTest(requires.serverless, !!process.env.SERVERLESS)
179+
) {
180+
return false;
181+
}
182+
170183
if (
171184
spec.operations.some(
172185
op => op.name === 'waitForEvent' && op.arguments.event === 'PoolReadyEvent'
@@ -191,20 +204,23 @@ function prepareDatabaseForSuite(suite, context) {
191204

192205
if (context.skipPrepareDatabase) return Promise.resolve();
193206

194-
const setupPromise = db
195-
.admin()
196-
.command({ killAllSessions: [] })
197-
.catch(err => {
198-
if (
199-
err.message.match(/no such (cmd|command)/) ||
200-
err.message.match(/Failed to kill on some hosts/) ||
201-
err.code === 11601
202-
) {
203-
return;
204-
}
207+
// Note: killAllSession is not supported on serverless, see CLOUDP-84298
208+
const setupPromise = context.serverless
209+
? Promise.resolve()
210+
: db
211+
.admin()
212+
.command({ killAllSessions: [] })
213+
.catch(err => {
214+
if (
215+
err.message.match(/no such (cmd|command)/) ||
216+
err.message.match(/Failed to kill on some hosts/) ||
217+
err.code === 11601
218+
) {
219+
return;
220+
}
205221

206-
throw err;
207-
});
222+
throw err;
223+
});
208224

209225
if (context.collectionName == null || context.dbName === 'admin') {
210226
return setupPromise;

0 commit comments

Comments
 (0)