Skip to content

Commit d6c201e

Browse files
durrannbbeeken
andauthored
test(NODE-3461): refactor lb manual to full test run (#2933)
Co-authored-by: Neal Beeken <[email protected]>
1 parent e69d992 commit d6c201e

File tree

10 files changed

+47
-32
lines changed

10 files changed

+47
-32
lines changed

.evergreen/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ functions:
169169
TOPOLOGY="${TOPOLOGY}" \
170170
SKIP_DEPS=${SKIP_DEPS|1} \
171171
NO_EXIT=${NO_EXIT|1} \
172-
TEST_NPM_SCRIPT="check:load-balancer" \
173172
FAKE_MONGODB_SERVICE_ID="true" \
174173
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
175174
run checks:

.evergreen/config.yml.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ functions:
192192
TOPOLOGY="${TOPOLOGY}" \
193193
SKIP_DEPS=${SKIP_DEPS|1} \
194194
NO_EXIT=${NO_EXIT|1} \
195-
TEST_NPM_SCRIPT="check:load-balancer" \
196195
FAKE_MONGODB_SERVICE_ID="true" \
197196
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
198197

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
"check:ts": "tsc -v && tsc --noEmit",
122122
"check:atlas": "mocha --config \"test/manual/mocharc.json\" test/manual/atlas_connectivity.test.js",
123123
"check:adl": "mocha test/manual/data_lake.test.js",
124-
"check:load-balancer": "mocha test/manual/load-balancer.test.js",
125124
"check:ocsp": "mocha --config \"test/manual/mocharc.json\" test/manual/ocsp_support.test.js",
126125
"check:kerberos": "mocha --config \"test/manual/mocharc.json\" test/manual/kerberos.test.js",
127126
"check:tls": "mocha --config \"test/manual/mocharc.json\" test/manual/tls_support.test.js",

src/db.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,11 @@ export class Db {
319319
* @param name - the collection name we wish to access.
320320
* @returns return the new Collection instance
321321
*/
322-
collection<TSchema extends Document = Document>(name: string): Collection<TSchema>;
323322
collection<TSchema extends Document = Document>(
324323
name: string,
325-
options?: CollectionOptions
324+
options: CollectionOptions = {}
326325
): Collection<TSchema> {
327-
if (!options) {
328-
options = {};
329-
} else if (typeof options === 'function') {
326+
if (typeof options === 'function') {
330327
// TODO(NODE-3485): Replace this with MongoDeprecationError
331328
throw new MongoDriverError('The callback form of this helper has been removed.');
332329
}

test/manual/load-balancer.test.js renamed to test/functional/load-balancer-spec.test.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@ const SKIP = [
1515
// in sub-optimal pinning.
1616
'pinned connections are not returned after an network error during getMore',
1717
'pinned connections are not returned to the pool after a non-network error on getMore',
18-
'stale errors are ignored'
18+
'stale errors are ignored',
19+
// NOTE: The driver correctly fails these 2 tests in non LB mode for server versions greater than 3.4.
20+
// In versions that are 3.4 or less an error still occurs but a different one (connection closes).
21+
// TODO(NODE-3543): fix the path-ing that will produce errors for older servers
22+
'operations against non-load balanced clusters fail if URI contains loadBalanced=true',
23+
'operations against non-load balanced clusters succeed if URI contains loadBalanced=false'
1924
];
2025

21-
require('../functional/retryable_reads.test');
22-
require('../functional/retryable_writes.test');
23-
require('../functional/uri_options_spec.test');
24-
require('../functional/change_stream_spec.test');
25-
require('../functional/versioned-api.test');
26-
require('../unit/core/mongodb_srv.test');
27-
require('../unit/sdam/server_selection/spec.test');
28-
2926
describe('Load Balancer Unified Tests', function () {
3027
this.timeout(10000);
3128
runUnifiedSuite(loadSpecTests(path.join('load-balancers')), SKIP);

test/functional/unified-spec-runner/entities.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
Collection,
55
GridFSBucket,
66
Document,
7-
HostAddress
7+
HostAddress,
8+
ServerApiVersion
89
} from '../../../src/index';
910
import { ReadConcern } from '../../../src/read_concern';
1011
import { WriteConcern } from '../../../src/write_concern';
@@ -30,7 +31,7 @@ import type {
3031
CommandStartedEvent,
3132
CommandSucceededEvent
3233
} from '../../../src/cmap/command_monitoring_events';
33-
import { patchCollectionOptions, patchDbOptions } from './unified-utils';
34+
import { makeConnectionString, patchCollectionOptions, patchDbOptions } from './unified-utils';
3435
import { expect } from 'chai';
3536
import { TestConfiguration, trace } from './runner';
3637

@@ -53,7 +54,7 @@ export type CmapEvent =
5354

5455
function serverApiConfig() {
5556
if (process.env.MONGODB_API_VERSION) {
56-
return { version: process.env.MONGODB_API_VERSION };
57+
return { version: process.env.MONGODB_API_VERSION as ServerApiVersion };
5758
}
5859
}
5960

@@ -102,12 +103,12 @@ export class UnifiedMongoClient extends MongoClient {
102103
connectionCheckedInEvent: 'connectionCheckedIn'
103104
} as const;
104105

105-
constructor(url: string, description: ClientEntity) {
106-
super(url, {
106+
constructor(uri: string, description: ClientEntity) {
107+
super(uri, {
107108
monitorCommands: true,
108-
...description.uriOptions,
109109
serverApi: description.serverApi ? description.serverApi : serverApiConfig()
110110
});
111+
111112
this.commandEvents = [];
112113
this.cmapEvents = [];
113114
this.failPoints = [];
@@ -329,7 +330,10 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
329330
const useMultipleMongoses =
330331
(config.topologyType === 'LoadBalanced' || config.topologyType === 'Sharded') &&
331332
entity.client.useMultipleMongoses;
332-
const uri = config.url({ useMultipleMongoses });
333+
const uri = makeConnectionString(
334+
config.url({ useMultipleMongoses }),
335+
entity.client.uriOptions
336+
);
333337
const client = new UnifiedMongoClient(uri, entity.client);
334338
await client.connect();
335339
map.set(entity.client.id, client);

test/functional/unified-spec-runner/match.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,29 +326,31 @@ export function expectErrorCheck(
326326
return;
327327
}
328328

329+
const expectMessage = `\n\nOriginal Error Stack:\n${error.stack}\n\n`;
330+
329331
if (expected.errorContains != null) {
330-
expect(error.message).to.include(expected.errorContains);
332+
expect(error.message, expectMessage).to.include(expected.errorContains);
331333
}
332334

333335
if (!(error instanceof MongoError)) {
334336
// if statement asserts type for TS, expect will always fail
335-
expect(error).to.be.instanceOf(MongoError);
337+
expect(error, expectMessage).to.be.instanceOf(MongoError);
336338
return;
337339
}
338340

339341
if (expected.errorCode != null) {
340-
expect(error).to.have.property('code', expected.errorCode);
342+
expect(error, expectMessage).to.have.property('code', expected.errorCode);
341343
}
342344

343345
if (expected.errorCodeName != null) {
344-
expect(error).to.have.property('codeName', expected.errorCodeName);
346+
expect(error, expectMessage).to.have.property('codeName', expected.errorCodeName);
345347
}
346348

347349
if (expected.errorLabelsContain != null) {
348350
for (const errorLabel of expected.errorLabelsContain) {
349351
expect(
350352
error.hasErrorLabel(errorLabel),
351-
`Error was supposed to have label ${errorLabel}, has [${error.errorLabels}]`
353+
`Error was supposed to have label ${errorLabel}, has [${error.errorLabels}] -- ${expectMessage}`
352354
).to.be.true;
353355
}
354356
}
@@ -357,7 +359,7 @@ export function expectErrorCheck(
357359
for (const errorLabel of expected.errorLabelsOmit) {
358360
expect(
359361
error.hasErrorLabel(errorLabel),
360-
`Error was supposed to have label ${errorLabel}, has [${error.errorLabels}]`
362+
`Error was supposed to have label ${errorLabel}, has [${error.errorLabels}] -- ${expectMessage}`
361363
).to.be.false;
362364
}
363365
}

test/functional/unified-spec-runner/schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ServerApiVersion } from '../../../src';
12
import type { Document, ObjectId } from '../../../src/bson';
23
import type { ReadConcernLevel } from '../../../src/read_concern';
34
import type { ReadPreferenceMode } from '../../../src/read_preference';
@@ -96,7 +97,7 @@ export type EntityDescription =
9697
| { stream: StreamEntity }
9798
| { session: SessionEntity };
9899
export interface ServerApi {
99-
version: string;
100+
version: ServerApiVersion;
100101
strict?: boolean;
101102
deprecationErrors?: boolean;
102103
}

test/functional/unified-spec-runner/unified-utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { gte as semverGte, lte as semverLte } from 'semver';
55
import { CollectionOptions, DbOptions, MongoClient } from '../../../src';
66
import { isDeepStrictEqual } from 'util';
77
import { TestConfiguration } from './runner';
8+
import ConnectionString from 'mongodb-connection-string-url';
89

910
const ENABLE_UNIFIED_TEST_LOGGING = false;
1011
export function log(message: unknown, ...optionalParameters: unknown[]): void {
@@ -98,3 +99,14 @@ export function translateOptions(options: Document): Document {
9899
}
99100
return translatedOptions as Document;
100101
}
102+
103+
export function makeConnectionString(
104+
uri: string,
105+
uriOptions: Record<string, unknown> = {}
106+
): string {
107+
const connectionString = new ConnectionString(uri);
108+
for (const [name, value] of Object.entries(uriOptions ?? {})) {
109+
connectionString.searchParams.set(name, String(value));
110+
}
111+
return connectionString.toString();
112+
}

test/tools/runner/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'use strict';
22

3+
require('source-map-support').install({
4+
hookRequire: true
5+
});
6+
37
const path = require('path');
48
const fs = require('fs');
59
const { MongoClient } = require('../../../src');
@@ -66,7 +70,8 @@ before(function (_done) {
6670
// );
6771

6872
const options = MONGODB_API_VERSION ? { serverApi: MONGODB_API_VERSION } : {};
69-
const client = new MongoClient(MONGODB_URI, options);
73+
const loadBalanced = SINGLE_MONGOS_LB_URI && MULTI_MONGOS_LB_URI;
74+
const client = new MongoClient(loadBalanced ? SINGLE_MONGOS_LB_URI : MONGODB_URI, options);
7075
const done = err => client.close(err2 => _done(err || err2));
7176

7277
client.connect(err => {

0 commit comments

Comments
 (0)