Skip to content

Commit 93a47fd

Browse files
authored
feat(NODE-3191): backport versioned api (#2850)
1 parent 33e8248 commit 93a47fd

File tree

106 files changed

+6850
-563
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+6850
-563
lines changed

.evergreen/config.yml

+26-45
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
stepback: true
22
command_type: system
3-
exec_timeout_secs: 1200
3+
exec_timeout_secs: 1500
44
timeout:
55
- command: shell.exec
66
params:
@@ -79,6 +79,7 @@ functions:
7979
MONGODB_VERSION=${VERSION} TOPOLOGY=${TOPOLOGY} \
8080
AUTH=${AUTH} SSL=${SSL} \
8181
ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \
82+
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
8283
bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
8384
- command: expansions.update
8485
params:
@@ -111,8 +112,10 @@ functions:
111112
rm -f ./prepare_client_encryption.sh
112113
fi
113114
114-
AUTH=${AUTH} SSL=${SSL} UNIFIED=${UNIFIED} MONGODB_URI="${MONGODB_URI}" \
115-
NODE_VERSION=${NODE_VERSION} SKIP_DEPS=1 NO_EXIT=1 \
115+
MONGODB_URI="${MONGODB_URI}" \
116+
AUTH=${AUTH} SSL=${SSL} UNIFIED=${UNIFIED} \
117+
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
118+
NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} NO_EXIT=${NO_EXIT|1} \
116119
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
117120
run checks:
118121
- command: shell.exec
@@ -496,39 +499,6 @@ post:
496499
ignore:
497500
- '*.md'
498501
tasks:
499-
- name: test-latest-server
500-
tags:
501-
- latest
502-
- server
503-
commands:
504-
- func: install dependencies
505-
- func: bootstrap mongo-orchestration
506-
vars:
507-
VERSION: latest
508-
TOPOLOGY: server
509-
- func: run tests
510-
- name: test-latest-replica_set
511-
tags:
512-
- latest
513-
- replica_set
514-
commands:
515-
- func: install dependencies
516-
- func: bootstrap mongo-orchestration
517-
vars:
518-
VERSION: latest
519-
TOPOLOGY: replica_set
520-
- func: run tests
521-
- name: test-latest-sharded_cluster
522-
tags:
523-
- latest
524-
- sharded_cluster
525-
commands:
526-
- func: install dependencies
527-
- func: bootstrap mongo-orchestration
528-
vars:
529-
VERSION: latest
530-
TOPOLOGY: sharded_cluster
531-
- func: run tests
532502
- name: test-latest-server-unified
533503
tags:
534504
- latest
@@ -1144,6 +1114,23 @@ tasks:
11441114
- func: run tests
11451115
vars:
11461116
UNIFIED: 1
1117+
- name: test-latest-server-v1-api
1118+
tags:
1119+
- latest
1120+
- server
1121+
- v1-api
1122+
commands:
1123+
- func: install dependencies
1124+
- func: bootstrap mongo-orchestration
1125+
vars:
1126+
VERSION: latest
1127+
TOPOLOGY: server
1128+
REQUIRE_API_VERSION: '1'
1129+
- func: run tests
1130+
vars:
1131+
MONGODB_API_VERSION: '1'
1132+
UNIFIED: 1
1133+
NO_EXIT: ''
11471134
- name: test-atlas-connectivity
11481135
tags:
11491136
- atlas-connect
@@ -1562,9 +1549,6 @@ buildvariants:
15621549
expansions:
15631550
NODE_LTS_NAME: fermium
15641551
tasks: &ref_0
1565-
- test-latest-server
1566-
- test-latest-replica_set
1567-
- test-latest-sharded_cluster
15681552
- test-latest-server-unified
15691553
- test-latest-replica_set-unified
15701554
- test-latest-sharded_cluster-unified
@@ -1616,6 +1600,7 @@ buildvariants:
16161600
- test-2.6-server-unified
16171601
- test-2.6-replica_set-unified
16181602
- test-2.6-sharded_cluster-unified
1603+
- test-latest-server-v1-api
16191604
- test-atlas-connectivity
16201605
- test-auth-kerberos-legacy
16211606
- test-auth-kerberos-unified
@@ -1672,9 +1657,6 @@ buildvariants:
16721657
expansions:
16731658
NODE_LTS_NAME: fermium
16741659
tasks: &ref_1
1675-
- test-latest-server
1676-
- test-latest-replica_set
1677-
- test-latest-sharded_cluster
16781660
- test-latest-server-unified
16791661
- test-latest-replica_set-unified
16801662
- test-latest-sharded_cluster-unified
@@ -1726,6 +1708,7 @@ buildvariants:
17261708
- test-2.6-server-unified
17271709
- test-2.6-replica_set-unified
17281710
- test-2.6-sharded_cluster-unified
1711+
- test-latest-server-v1-api
17291712
- test-atlas-connectivity
17301713
- test-auth-kerberos-legacy
17311714
- test-auth-kerberos-unified
@@ -1859,9 +1842,6 @@ buildvariants:
18591842
NODE_LTS_NAME: fermium
18601843
CLIENT_ENCRYPTION: true
18611844
tasks: &ref_3
1862-
- test-latest-server
1863-
- test-latest-replica_set
1864-
- test-latest-sharded_cluster
18651845
- test-latest-server-unified
18661846
- test-latest-replica_set-unified
18671847
- test-latest-sharded_cluster-unified
@@ -1901,6 +1881,7 @@ buildvariants:
19011881
- test-3.2-server-unified
19021882
- test-3.2-replica_set-unified
19031883
- test-3.2-sharded_cluster-unified
1884+
- test-latest-server-v1-api
19041885
- test-atlas-connectivity
19051886
- test-auth-kerberos-legacy
19061887
- test-auth-kerberos-unified

.evergreen/config.yml.in

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ command_type: system
1111
# Protect ourself against rogue test case, or curl gone wild, that runs forever
1212
# Good rule of thumb: the averageish length a task takes, times 5
1313
# That roughly accounts for variable system performance for various buildvariants
14-
exec_timeout_secs: 1200
14+
exec_timeout_secs: 1500
1515

1616
# What to do when evergreen hits the timeout (`post:` tasks are run automatically)
1717
timeout:
@@ -96,6 +96,7 @@ functions:
9696
MONGODB_VERSION=${VERSION} TOPOLOGY=${TOPOLOGY} \
9797
AUTH=${AUTH} SSL=${SSL} \
9898
ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \
99+
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
99100
bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
100101
# run-orchestration generates expansion file with the MONGODB_URI for the cluster
101102
- command: expansions.update
@@ -130,8 +131,10 @@ functions:
130131
rm -f ./prepare_client_encryption.sh
131132
fi
132133

133-
AUTH=${AUTH} SSL=${SSL} UNIFIED=${UNIFIED} MONGODB_URI="${MONGODB_URI}" \
134-
NODE_VERSION=${NODE_VERSION} SKIP_DEPS=1 NO_EXIT=1 \
134+
MONGODB_URI="${MONGODB_URI}" \
135+
AUTH=${AUTH} SSL=${SSL} UNIFIED=${UNIFIED} \
136+
MONGODB_API_VERSION="${MONGODB_API_VERSION}" \
137+
NODE_VERSION=${NODE_VERSION} SKIP_DEPS=${SKIP_DEPS|1} NO_EXIT=${NO_EXIT|1} \
135138
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
136139

137140
"run checks":

.evergreen/generate_evergreen_tasks.js

+37-8
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ const fs = require('fs');
55
const yaml = require('js-yaml');
66

77
const LATEST_EFFECTIVE_VERSION = '5.0';
8-
const MONGODB_VERSIONS = ['latest', '4.4', '4.2', '4.0', '3.6', '3.4', '3.2', '3.0', '2.6'];
8+
const LEGACY_MONGODB_VERSIONS = new Set(['4.4', '4.2', '4.0', '3.6', '3.4', '3.2', '3.0', '2.6']);
9+
const MONGODB_VERSIONS = ['latest'].concat(Array.from(LEGACY_MONGODB_VERSIONS));
910
const AWS_AUTH_VERSIONS = ['latest', '4.4'];
1011
const OCSP_VERSIONS = ['latest', '4.4'];
1112
const TLS_VERSIONS = ['latest', '4.2']; // also test on 4.2 because 4.4+ currently skipped on windows
1213
const NODE_VERSIONS = ['fermium', 'erbium', 'dubnium', 'carbon', 'boron', 'argon'];
13-
const TOPOLOGIES = ['server', 'replica_set', 'sharded_cluster'].concat([
14-
'server-unified',
15-
'replica_set-unified',
16-
'sharded_cluster-unified'
17-
]);
14+
const LEGACY_TOPOLOGIES = new Set(['server', 'replica_set', 'sharded_cluster']);
15+
const UNIFIED_TOPOLOGIES = Array.from(LEGACY_TOPOLOGIES).map(topology => `${topology}-unified`);
16+
1817

1918
const OPERATING_SYSTEMS = [
2019
{
@@ -74,6 +73,7 @@ const OPERATING_SYSTEMS = [
7473
)
7574
);
7675

76+
// TODO: NODE-3060: enable skipped tests on windows
7777
const WINDOWS_SKIP_TAGS = new Set([
7878
'atlas-connect',
7979
'auth'
@@ -109,9 +109,38 @@ function makeTask({ mongoVersion, topology }) {
109109
}
110110

111111
MONGODB_VERSIONS.forEach(mongoVersion => {
112-
TOPOLOGIES.forEach(topology =>
112+
Array.from(LEGACY_TOPOLOGIES).concat(UNIFIED_TOPOLOGIES).forEach(topology => {
113+
if (LEGACY_TOPOLOGIES.has(topology) && !LEGACY_MONGODB_VERSIONS.has(mongoVersion)) {
114+
// MongoDB 5.0+ is only supported by the Unified Topology in driver 3.7+
115+
// therefore testing the legacy toplogy can be skipped
116+
return;
117+
}
113118
BASE_TASKS.push(makeTask({ mongoVersion, topology }))
114-
);
119+
});
120+
});
121+
122+
BASE_TASKS.push({
123+
name: `test-latest-server-v1-api`,
124+
tags: ['latest', 'server', 'v1-api'],
125+
commands: [
126+
{ func: 'install dependencies' },
127+
{
128+
func: 'bootstrap mongo-orchestration',
129+
vars: {
130+
VERSION: 'latest',
131+
TOPOLOGY: 'server',
132+
REQUIRE_API_VERSION: '1'
133+
}
134+
},
135+
{
136+
func: 'run tests',
137+
vars: {
138+
MONGODB_API_VERSION: '1',
139+
UNIFIED: 1,
140+
NO_EXIT: ''
141+
}
142+
}
143+
]
115144
});
116145

117146
TASKS.push(

.evergreen/run-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ nvm use 12
5959
npm run build:unified
6060
nvm use "$NODE_VERSION"
6161

62-
MONGODB_UNIFIED_TOPOLOGY=${UNIFIED} MONGODB_URI=${MONGODB_URI} npm run ${TEST_NPM_SCRIPT}
62+
MONGODB_API_VERSION=${MONGODB_API_VERSION} MONGODB_UNIFIED_TOPOLOGY=${UNIFIED} MONGODB_URI=${MONGODB_URI} npm run ${TEST_NPM_SCRIPT}

lib/cmap/connection.js

+34-7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class Connection extends EventEmitter {
3737
this.port = options.port || 27017;
3838
this.monitorCommands =
3939
typeof options.monitorCommands === 'boolean' ? options.monitorCommands : false;
40+
this.serverApi = options.serverApi;
41+
4042
this.closed = false;
4143
this.destroyed = false;
4244

@@ -170,33 +172,58 @@ class Connection extends EventEmitter {
170172
});
171173
}
172174

175+
applyApiVersion(options) {
176+
if (this.serverApi) {
177+
options.serverApi = this.serverApi;
178+
}
179+
return options;
180+
}
181+
173182
// Wire protocol methods
174183
command(ns, cmd, options, callback) {
175-
wp.command(makeServerTrampoline(this), ns, cmd, options, callback);
184+
if (typeof options === 'function') {
185+
callback = options;
186+
options = {};
187+
}
188+
wp.command(makeServerTrampoline(this), ns, cmd, this.applyApiVersion(options), callback);
176189
}
177190

178191
query(ns, cmd, cursorState, options, callback) {
179-
wp.query(makeServerTrampoline(this), ns, cmd, cursorState, options, callback);
192+
wp.query(
193+
makeServerTrampoline(this),
194+
ns,
195+
cmd,
196+
cursorState,
197+
this.applyApiVersion(options),
198+
callback
199+
);
180200
}
181201

182202
getMore(ns, cursorState, batchSize, options, callback) {
183-
wp.getMore(makeServerTrampoline(this), ns, cursorState, batchSize, options, callback);
203+
wp.getMore(
204+
makeServerTrampoline(this),
205+
ns,
206+
cursorState,
207+
batchSize,
208+
this.applyApiVersion(options),
209+
callback
210+
);
184211
}
185212

186213
killCursors(ns, cursorState, callback) {
187-
wp.killCursors(makeServerTrampoline(this), ns, cursorState, callback);
214+
wp.killCursors(makeServerTrampoline(this), ns, cursorState, this.applyApiVersion({}), callback);
188215
}
189216

190217
insert(ns, ops, options, callback) {
191-
wp.insert(makeServerTrampoline(this), ns, ops, options, callback);
218+
wp.insert(makeServerTrampoline(this), ns, ops, this.applyApiVersion(options), callback);
192219
}
193220

194221
update(ns, ops, options, callback) {
195-
wp.update(makeServerTrampoline(this), ns, ops, options, callback);
222+
wp.update(makeServerTrampoline(this), ns, ops, this.applyApiVersion(options), callback);
196223
}
197224

198225
remove(ns, ops, options, callback) {
199-
wp.remove(makeServerTrampoline(this), ns, ops, options, callback);
226+
wp.remove(makeServerTrampoline(this), ns, ops, this.applyApiVersion(options), callback);
200227
}
201228
}
202229

lib/cmap/connection_pool.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const VALID_POOL_OPTIONS = new Set([
4141
'ssl',
4242
'bson',
4343
'connectionType',
44+
'serverApi',
4445
'monitorCommands',
4546
'socketTimeout',
4647
'credentials',

lib/collection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ Collection.prototype.count = deprecate(function(query, options, callback) {
15241524

15251525
return executeOperation(
15261526
this.s.topology,
1527-
new EstimatedDocumentCountOperation(this, query, options),
1527+
new EstimatedDocumentCountOperation(this, Object.assign({ query }, options)),
15281528
callback
15291529
);
15301530
}, 'collection.count is deprecated, and will be removed in a future version.' +

0 commit comments

Comments
 (0)