Skip to content

Commit a0c7f5c

Browse files
authored
test(NODE-3735): update to use serverless uri (#3359)
1 parent cf88463 commit a0c7f5c

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

.evergreen/config.in.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,17 @@ functions:
197197
export SERVERLESS="1"
198198
export SERVERLESS_ATLAS_USER="${SERVERLESS_ATLAS_USER}"
199199
export SERVERLESS_ATLAS_PASSWORD="${SERVERLESS_ATLAS_PASSWORD}"
200+
export SERVERLESS_URI="${SERVERLESS_URI}"
200201
201-
export SINGLE_ATLASPROXY_SERVERLESS_URI="${SINGLE_ATLASPROXY_SERVERLESS_URI}"
202-
export MULTI_ATLASPROXY_SERVERLESS_URI="${MULTI_ATLASPROXY_SERVERLESS_URI}"
202+
echo "setting SERVERLESS_URI: $SERVERLESS_URI"
203203
204-
export MONGODB_URI="${SINGLE_ATLASPROXY_SERVERLESS_URI}"
205-
export SINGLE_MONGOS_LB_URI="${SINGLE_ATLASPROXY_SERVERLESS_URI}"
204+
export MONGODB_URI="${SERVERLESS_URI}"
205+
export SINGLE_MONGOS_LB_URI="${SERVERLESS_URI}"
206206
207-
# Setting MULTI_MONGOS to the SINGLE_ATLAS is intentional
207+
# Setting MULTI_MONGOS to the SERVERLESS_URI is intentional
208208
# LB tests pick one host out of the comma separated list
209209
# so just passing the one host is equivalent
210-
export MULTI_MONGOS_LB_URI="${SINGLE_ATLASPROXY_SERVERLESS_URI}"
210+
export MULTI_MONGOS_LB_URI="${SERVERLESS_URI}"
211211
212212
bash ${PROJECT_DIRECTORY}/.evergreen/run-serverless-tests.sh
213213

.evergreen/config.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,17 @@ functions:
176176
export SERVERLESS="1"
177177
export SERVERLESS_ATLAS_USER="${SERVERLESS_ATLAS_USER}"
178178
export SERVERLESS_ATLAS_PASSWORD="${SERVERLESS_ATLAS_PASSWORD}"
179+
export SERVERLESS_URI="${SERVERLESS_URI}"
179180
180-
export SINGLE_ATLASPROXY_SERVERLESS_URI="${SINGLE_ATLASPROXY_SERVERLESS_URI}"
181-
export MULTI_ATLASPROXY_SERVERLESS_URI="${MULTI_ATLASPROXY_SERVERLESS_URI}"
181+
echo "setting SERVERLESS_URI: $SERVERLESS_URI"
182182
183-
export MONGODB_URI="${SINGLE_ATLASPROXY_SERVERLESS_URI}"
184-
export SINGLE_MONGOS_LB_URI="${SINGLE_ATLASPROXY_SERVERLESS_URI}"
183+
export MONGODB_URI="${SERVERLESS_URI}"
184+
export SINGLE_MONGOS_LB_URI="${SERVERLESS_URI}"
185185
186-
# Setting MULTI_MONGOS to the SINGLE_ATLAS is intentional
186+
# Setting MULTI_MONGOS to the SERVERLESS_URI is intentional
187187
# LB tests pick one host out of the comma separated list
188188
# so just passing the one host is equivalent
189-
export MULTI_MONGOS_LB_URI="${SINGLE_ATLASPROXY_SERVERLESS_URI}"
189+
export MULTI_MONGOS_LB_URI="${SERVERLESS_URI}"
190190
191191
bash ${PROJECT_DIRECTORY}/.evergreen/run-serverless-tests.sh
192192
start-load-balancer:

.evergreen/run-serverless-tests.sh

100644100755
+5-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
source "${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh"
44

55
if [ -z ${SERVERLESS+omitted} ]; then echo "SERVERLESS is unset" && exit 1; fi
6-
if [ -z ${MULTI_ATLASPROXY_SERVERLESS_URI+omitted} ]; then echo "MULTI_ATLASPROXY_SERVERLESS_URI is unset" && exit 1; fi
7-
if [ -z ${SINGLE_ATLASPROXY_SERVERLESS_URI+omitted} ]; then echo "SINGLE_ATLASPROXY_SERVERLESS_URI is unset" && exit 1; fi
6+
if [ -z ${SERVERLESS_URI+omitted} ]; then echo "SERVERLESS_URI is unset" && exit 1; fi
87
if [ -z ${SINGLE_MONGOS_LB_URI+omitted} ]; then echo "SINGLE_MONGOS_LB_URI is unset" && exit 1; fi
98
if [ -z ${MULTI_MONGOS_LB_URI+omitted} ]; then echo "MULTI_MONGOS_LB_URI is unset" && exit 1; fi
109
if [ -z ${MONGODB_URI+omitted} ]; then echo "MONGODB_URI is unset" && exit 1; fi
@@ -16,10 +15,10 @@ npx mocha \
1615
test/integration/crud/crud.spec.test.js \
1716
test/integration/crud/crud.prose.test.js \
1817
test/integration/retryable-reads/retryable_reads.spec.test.js \
19-
test/integration/retryable-writes/retryable_writes.spec.test.js \
20-
test/integration/sessions/sessions.spec.test.js \
21-
test/integration/sessions/sessions.test.js \
18+
test/integration/retryable-writes/retryable_writes.spec.test.ts \
19+
test/integration/sessions/sessions.spec.test.ts \
20+
test/integration/sessions/sessions.test.ts \
2221
test/integration/transactions/transactions.spec.test.js \
23-
test/integration/transactions/transactions.test.js \
22+
test/integration/transactions/transactions.test.ts \
2423
test/integration/versioned-api/versioned_api.spec.test.js \
2524
test/integration/load-balancers/load_balancers.spec.test.js

test/readme.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ The following steps will walk you through how to create and test a MongoDB Serve
231231
AUTH: xxx
232232
TOPOLOGY: xxx
233233
SERVERLESS: xxx
234-
MULTI_ATLASPROXY_SERVERLESS_URI: xxx
235-
SINGLE_ATLASPROXY_SERVERLESS_URI: xxx
234+
SERVERLESS_URI: xxx
236235
```
237236
238237
1. Generate a sourceable environment file from `serverless-expansion.yml` by running the following command:
@@ -245,9 +244,9 @@ The following steps will walk you through how to create and test a MongoDB Serve
245244

246245
1. Update the following variables in `serverless.env`, so that they are equivalent to what our Evergreen builds do:
247246

248-
- Change `MONGODB_URI` to have the same value as `SINGLE_ATLASPROXY_SERVERLESS_URI`.
249-
- Add `SINGLE_MONGOS_LB_URI` and set it to the value of `SINGLE_ATLASPROXY_SERVERLESS_URI`.
250-
- Add `MULTI_MONGOS_LB_URI` and set it to the value of `SINGLE_ATLASPROXY_SERVERLESS_URI`.
247+
- Change `MONGODB_URI` to have the same value as `SERVERLESS_URI`.
248+
- Add `SINGLE_MONGOS_LB_URI` and set it to the value of `SERVERLESS_URI`.
249+
- Add `MULTI_MONGOS_LB_URI` and set it to the value of `SERVERLESS_URI`.
251250

252251
1. Source the environment variables using a command like `source serverless.env`.
253252

test/tools/runner/config.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ export class TestConfiguration {
8787
hostAddresses,
8888
hostAddress: hostAddresses[0],
8989
host: hostAddresses[0].host,
90-
port: typeof hostAddresses[0].host === 'string' ? hostAddresses[0].port : undefined,
90+
port:
91+
typeof hostAddresses[0].host === 'string' && !this.isServerless
92+
? hostAddresses[0].port
93+
: undefined,
9194
db: url.pathname.slice(1) ? url.pathname.slice(1) : 'integration_tests',
9295
replicaSet: url.searchParams.get('replicaSet'),
9396
proxyURIParams: url.searchParams.get('proxyHost')
@@ -112,7 +115,9 @@ export class TestConfiguration {
112115
}
113116

114117
get isLoadBalanced() {
115-
return !!this.singleMongosLoadBalancerUri && !!this.multiMongosLoadBalancerUri;
118+
return (
119+
!!this.singleMongosLoadBalancerUri && !!this.multiMongosLoadBalancerUri && !this.isServerless
120+
);
116121
}
117122

118123
writeConcern() {
@@ -194,7 +199,7 @@ export class TestConfiguration {
194199
delete dbOptions.writeConcern;
195200
}
196201

197-
if (this.topologyType === TopologyType.LoadBalanced) {
202+
if (this.topologyType === TopologyType.LoadBalanced && !this.isServerless) {
198203
dbOptions.loadBalanced = true;
199204
}
200205

@@ -203,10 +208,10 @@ export class TestConfiguration {
203208
}
204209

205210
const urlOptions: url.UrlObject = {
206-
protocol: 'mongodb',
211+
protocol: this.isServerless ? 'mongodb+srv' : 'mongodb',
207212
slashes: true,
208213
hostname: dbHost,
209-
port: dbPort,
214+
port: this.isServerless ? null : dbPort,
210215
query: dbOptions,
211216
pathname: '/'
212217
};
@@ -267,7 +272,8 @@ export class TestConfiguration {
267272

268273
const FILLER_HOST = 'fillerHost';
269274

270-
const url = new URL(`mongodb://${FILLER_HOST}`);
275+
const protocol = this.isServerless ? 'mongodb+srv' : 'mongodb';
276+
const url = new URL(`${protocol}://${FILLER_HOST}`);
271277

272278
if (options.replicaSet) {
273279
url.searchParams.append('replicaSet', options.replicaSet);
@@ -294,7 +300,7 @@ export class TestConfiguration {
294300
url.password = password;
295301
}
296302

297-
if (this.isLoadBalanced) {
303+
if (this.isLoadBalanced && !this.isServerless) {
298304
url.searchParams.append('loadBalanced', 'true');
299305
}
300306

@@ -319,7 +325,8 @@ export class TestConfiguration {
319325
}
320326

321327
let actualHostsString;
322-
if (options.useMultipleMongoses) {
328+
// Ignore multi mongos options in serverless testing.
329+
if (options.useMultipleMongoses && !this.isServerless) {
323330
if (this.isLoadBalanced) {
324331
const multiUri = new ConnectionString(this.multiMongosLoadBalancerUri);
325332
if (multiUri.isSRV) {
@@ -331,7 +338,7 @@ export class TestConfiguration {
331338
actualHostsString = this.options.hostAddresses.map(ha => ha.toString()).join(',');
332339
}
333340
} else {
334-
if (this.isLoadBalanced) {
341+
if (this.isLoadBalanced || this.isServerless) {
335342
const singleUri = new ConnectionString(this.singleMongosLoadBalancerUri);
336343
actualHostsString = singleUri.hosts[0].toString();
337344
} else {

0 commit comments

Comments
 (0)