Skip to content

Commit 6970871

Browse files
authored
refactor(NODE-3845): update load balancer config (#3089)
1 parent c63a21b commit 6970871

File tree

12 files changed

+77
-49
lines changed

12 files changed

+77
-49
lines changed

.evergreen/config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ functions:
8282
AUTH=${AUTH} SSL=${SSL} \
8383
ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \
8484
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
85+
LOAD_BALANCER=${LOAD_BALANCER} \
8586
bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
8687
- command: expansions.update
8788
params:
@@ -201,7 +202,7 @@ functions:
201202
TOPOLOGY="${TOPOLOGY}" \
202203
SKIP_DEPS=${SKIP_DEPS|1} \
203204
NO_EXIT=${NO_EXIT|1} \
204-
FAKE_MONGODB_SERVICE_ID="true" \
205+
LOAD_BALANCER="${LOAD_BALANCER}" \
205206
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
206207
run checks:
207208
- command: shell.exec
@@ -972,8 +973,9 @@ tasks:
972973
- func: install dependencies
973974
- func: bootstrap mongo-orchestration
974975
vars:
975-
VERSION: '5.0'
976+
VERSION: latest
976977
TOPOLOGY: sharded_cluster
978+
LOAD_BALANCER: 'true'
977979
- func: start-load-balancer
978980
- func: run-lb-tests
979981
- func: stop-load-balancer

.evergreen/config.yml.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ functions:
9999
AUTH=${AUTH} SSL=${SSL} \
100100
ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \
101101
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
102+
LOAD_BALANCER=${LOAD_BALANCER} \
102103
bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
103104
# run-orchestration generates expansion file with the MONGODB_URI for the cluster
104105
- command: expansions.update
@@ -225,7 +226,7 @@ functions:
225226
TOPOLOGY="${TOPOLOGY}" \
226227
SKIP_DEPS=${SKIP_DEPS|1} \
227228
NO_EXIT=${NO_EXIT|1} \
228-
FAKE_MONGODB_SERVICE_ID="true" \
229+
LOAD_BALANCER="${LOAD_BALANCER}" \
229230
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
230231

231232
"run checks":

.evergreen/generate_evergreen_tasks.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ TASKS.push(
117117
{
118118
func: 'bootstrap mongo-orchestration',
119119
vars: {
120-
VERSION: '5.0',
121-
TOPOLOGY: 'sharded_cluster'
120+
VERSION: 'latest',
121+
TOPOLOGY: 'sharded_cluster',
122+
LOAD_BALANCER: 'true'
122123
}
123124
},
124125
{ func: 'start-load-balancer' },

.evergreen/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ else
5050
. $DRIVERS_TOOLS/.evergreen/csfle/set-temp-creds.sh
5151
fi
5252

53-
SINGLE_MONGOS_LB_URI=${SINGLE_MONGOS_LB_URI} MULTI_MONGOS_LB_URI=${MULTI_MONGOS_LB_URI} MONGODB_API_VERSION=${MONGODB_API_VERSION} MONGODB_UNIFIED_TOPOLOGY=${UNIFIED} MONGODB_URI=${MONGODB_URI} npm run ${TEST_NPM_SCRIPT}
53+
SINGLE_MONGOS_LB_URI=${SINGLE_MONGOS_LB_URI} MULTI_MONGOS_LB_URI=${MULTI_MONGOS_LB_URI} MONGODB_API_VERSION=${MONGODB_API_VERSION} MONGODB_UNIFIED_TOPOLOGY=${UNIFIED} MONGODB_URI=${MONGODB_URI} LOAD_BALANCER=${LOAD_BALANCER} npm run ${TEST_NPM_SCRIPT}

global.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import type { TestConfiguration } from './test/tools/unified-spec-runner/runner';
22

3+
type WithExclusion<T extends string> = `!${T}`
34
/** Defined in test/tools/runner/filters/mongodb_topology_filter.js (topologyTypeToString) */
45
type TopologyTypes = 'single' | 'replicaset' | 'sharded' | 'load-balanced';
6+
type TopologyTypeRequirement = WithExclusion<TopologyTypes> | WithExclusion<TopologyTypes>[]
57

68
interface MongoDBMetadataUI {
79
requires?: {
8-
topology?: TopologyTypes | TopologyTypes[];
10+
topology?: TopologyTypeRequirement;
911
mongodb?: string;
1012
os?: NodeJS.Platform | `!${NodeJS.Platform}`;
1113
apiVersion?: '1';
@@ -58,7 +60,7 @@ declare global {
5860
* - my test
5961
* - TODO(NODE-XXXX): Feature implementation impending!
6062
* ```
61-
*
63+
*
6264
* You can also skip a set of tests via beforeEach:
6365
* ```
6466
* beforeEach(() => {

src/cmap/connect.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ const AUTH_PROVIDERS = new Map<AuthMechanism | string, AuthProvider>([
5050
[AuthMechanism.MONGODB_X509, new X509()]
5151
]);
5252

53-
const FAKE_MONGODB_SERVICE_ID =
54-
typeof process.env.FAKE_MONGODB_SERVICE_ID === 'string' &&
55-
process.env.FAKE_MONGODB_SERVICE_ID.toLowerCase() === 'true';
56-
5753
/** @public */
5854
export type Stream = Socket | TLSSocket;
5955

@@ -163,10 +159,6 @@ function performInitialHandshake(
163159
}
164160

165161
if (options.loadBalanced) {
166-
// TODO: Durran: Remove when server support exists. (NODE-3431)
167-
if (FAKE_MONGODB_SERVICE_ID) {
168-
response.serviceId = response.topologyVersion.processId;
169-
}
170162
if (!response.serviceId) {
171163
return callback(
172164
new MongoCompatibilityError(

test/integration/connection-monitoring-and-pooling/connection.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('Connection', function () {
1616

1717
describe('Connection - functional/cmap', function () {
1818
it('should execute a command against a server', {
19-
metadata: { requires: { apiVersion: false } },
19+
metadata: { requires: { apiVersion: false, topology: '!load-balanced' } },
2020
test: function (done) {
2121
const connectOptions = Object.assign(
2222
{ connectionType: Connection },
@@ -38,7 +38,7 @@ describe('Connection', function () {
3838
});
3939

4040
it('should emit command monitoring events', {
41-
metadata: { requires: { apiVersion: false } },
41+
metadata: { requires: { apiVersion: false, topology: '!load-balanced' } },
4242
test: function (done) {
4343
const connectOptions = Object.assign(
4444
{ connectionType: Connection, monitorCommands: true },

test/integration/node-specific/topology.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { expect } = require('chai');
33

44
describe('Topology', function () {
55
it('should correctly track states of a topology', {
6-
metadata: { requires: { apiVersion: false } }, // apiVersion not supported by newTopology()
6+
metadata: { requires: { apiVersion: false, topology: '!load-balanced' } }, // apiVersion not supported by newTopology()
77
test: function (done) {
88
const topology = this.configuration.newTopology();
99

test/tools/runner/filters/mongodb_topology_filter.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,25 @@ class MongoDBTopologyFilter {
4040
);
4141
}
4242

43-
return topologies.some(topology => topology === this.runtimeTopology);
43+
const isExclusion = topologies[0][0] === '!';
44+
if (isExclusion) {
45+
if (!topologies.every(topology => topology.startsWith('!'))) {
46+
// Not every topology starts with !
47+
throw new Error('Cannot combine inclusion with exclusion of topologies');
48+
}
49+
50+
// Every excluded topology does not equal the current (prefix !)
51+
return topologies.every(topology => topology !== `!${this.runtimeTopology}`);
52+
} else {
53+
// inclusion list
54+
if (topologies.some(topology => topology.startsWith('!'))) {
55+
// Some topologies start with !
56+
throw new Error('Cannot combine exclusion with inclusion of topologies');
57+
}
58+
59+
// At least some (one) of the included topologies equals the current
60+
return topologies.some(topology => topology === this.runtimeTopology);
61+
}
4462
}
4563
}
4664

test/tools/runner/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ before(async function () {
9393
context.multiMongosLoadBalancerUri = MULTI_MONGOS_LB_URI;
9494
}
9595

96-
this.configuration = new TestConfiguration(MONGODB_URI, context);
96+
this.configuration = new TestConfiguration(
97+
loadBalanced ? SINGLE_MONGOS_LB_URI : MONGODB_URI,
98+
context
99+
);
97100
await client.close();
98101
});
99102

0 commit comments

Comments
 (0)