diff --git a/src/connection_string.ts b/src/connection_string.ts index ce20b9e90a9..d50a1fcfa94 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -249,13 +249,6 @@ export function parseOptions( const mongoOptions = Object.create(null); - // Feature flags - for (const flag of Object.getOwnPropertySymbols(options)) { - if (FEATURE_FLAGS.has(flag)) { - mongoOptions[flag] = options[flag]; - } - } - mongoOptions.hosts = isSRV ? [] : hosts.map(HostAddress.fromString); const urlOptions = new CaseInsensitiveMap(); @@ -515,12 +508,11 @@ export function parseOptions( ); } - const loggerFeatureFlag = Symbol.for('@@mdb.enableMongoLogger'); - mongoOptions[loggerFeatureFlag] = mongoOptions[loggerFeatureFlag] ?? false; + mongoOptions.__enableMongoLogger = mongoOptions.__enableMongoLogger ?? false; let loggerEnvOptions: MongoLoggerEnvOptions = {}; let loggerClientOptions: MongoLoggerMongoClientOptions = {}; - if (mongoOptions[loggerFeatureFlag]) { + if (mongoOptions.__enableMongoLogger) { loggerEnvOptions = { MONGODB_LOG_COMMAND: process.env.MONGODB_LOG_COMMAND, MONGODB_LOG_TOPOLOGY: process.env.MONGODB_LOG_TOPOLOGY, @@ -530,7 +522,7 @@ export function parseOptions( MONGODB_LOG_ALL: process.env.MONGODB_LOG_ALL, MONGODB_LOG_MAX_DOCUMENT_LENGTH: process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH, MONGODB_LOG_PATH: process.env.MONGODB_LOG_PATH, - ...mongoOptions[Symbol.for('@@mdb.internalLoggerConfig')] + ...mongoOptions.__internalLoggerConfig }; loggerClientOptions = { mongodbLogPath: mongoOptions.mongodbLogPath, @@ -1317,7 +1309,10 @@ export const OPTIONS = { * @internal * TODO: NODE-5671 - remove internal flag */ - mongodbLogMaxDocumentLength: { type: 'uint' } + mongodbLogMaxDocumentLength: { type: 'uint' }, + __enableMongoLogger: { type: 'boolean' }, + __skipPingOnConnect: { type: 'boolean' }, + __internalLoggerConfig: { type: 'record' } } as Record; export const DEFAULT_OPTIONS = new CaseInsensitiveMap( @@ -1325,13 +1320,3 @@ export const DEFAULT_OPTIONS = new CaseInsensitiveMap( .filter(([, descriptor]) => descriptor.default != null) .map(([k, d]) => [k, d.default]) ); - -/** - * Set of permitted feature flags - * @internal - */ -export const FEATURE_FLAGS = new Set([ - Symbol.for('@@mdb.skipPingOnConnect'), - Symbol.for('@@mdb.enableMongoLogger'), - Symbol.for('@@mdb.internalLoggerConfig') -]); diff --git a/src/mongo_client.ts b/src/mongo_client.ts index dea069cc949..61cc94d94cd 100644 --- a/src/mongo_client.ts +++ b/src/mongo_client.ts @@ -26,6 +26,7 @@ import { type LogComponentSeveritiesClientOptions, type MongoDBLogWritable, MongoLogger, + type MongoLoggerEnvOptions, type MongoLoggerOptions, SeverityLevel } from './mongo_logger'; @@ -299,7 +300,11 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC mongodbLogMaxDocumentLength?: number; /** @internal */ - [featureFlag: symbol]: any; + __skipPingOnConnect?: boolean; + /** @internal */ + __internalLoggerConfig?: MongoLoggerEnvOptions; + /** @internal */ + __enableMongoLogger?: boolean; } /** @public */ @@ -1006,9 +1011,6 @@ export interface MongoOptions tlsCRLFile?: string; tlsCertificateKeyFile?: string; - /** @internal */ - [featureFlag: symbol]: any; - /** * @internal * TODO: NODE-5671 - remove internal flag @@ -1020,4 +1022,10 @@ export interface MongoOptions */ mongodbLogPath?: 'stderr' | 'stdout' | MongoDBLogWritable; timeoutMS?: number; + /** @internal */ + __skipPingOnConnect?: boolean; + /** @internal */ + __internalLoggerConfig?: Document; + /** @internal */ + __enableMongoLogger?: boolean; } diff --git a/src/operations/execute_operation.ts b/src/operations/execute_operation.ts index f59df27569f..81601a6e160 100644 --- a/src/operations/execute_operation.ts +++ b/src/operations/execute_operation.ts @@ -131,7 +131,7 @@ async function autoConnect(client: MongoClient): Promise { if (client.s.hasBeenClosed) { throw new MongoNotConnectedError('Client must be connected before running operations'); } - client.s.options[Symbol.for('@@mdb.skipPingOnConnect')] = true; + client.s.options.__skipPingOnConnect = true; try { await client.connect(); if (client.topology == null) { @@ -141,7 +141,7 @@ async function autoConnect(client: MongoClient): Promise { } return client.topology; } finally { - delete client.s.options[Symbol.for('@@mdb.skipPingOnConnect')]; + delete client.s.options.__skipPingOnConnect; } } return client.topology; diff --git a/src/sdam/topology.ts b/src/sdam/topology.ts index 61a3bb84fec..b6cad4097e8 100644 --- a/src/sdam/topology.ts +++ b/src/sdam/topology.ts @@ -3,7 +3,7 @@ import type { MongoCredentials } from '../cmap/auth/mongo_credentials'; import type { ConnectionEvents } from '../cmap/connection'; import type { ConnectionPoolEvents } from '../cmap/connection_pool'; import type { ClientMetadata } from '../cmap/handshake/client_metadata'; -import { DEFAULT_OPTIONS, FEATURE_FLAGS } from '../connection_string'; +import { DEFAULT_OPTIONS } from '../connection_string'; import { CLOSE, CONNECT, @@ -153,7 +153,7 @@ export interface TopologyOptions extends BSONSerializeOptions, ServerOptions { serverMonitoringMode: ServerMonitoringMode; /** MongoDB server API version */ serverApi?: ServerApi; - [featureFlag: symbol]: any; + __skipPingOnConnect?: boolean; } /** @public */ @@ -251,8 +251,7 @@ export class Topology extends TypedEventEmitter { // Options should only be undefined in tests, MongoClient will always have defined options options = options ?? { hosts: [HostAddress.fromString('localhost:27017')], - ...Object.fromEntries(DEFAULT_OPTIONS.entries()), - ...Object.fromEntries(FEATURE_FLAGS.entries()) + ...Object.fromEntries(DEFAULT_OPTIONS.entries()) }; if (typeof seeds === 'string') { @@ -466,7 +465,7 @@ export class Topology extends TypedEventEmitter { readPreferenceServerSelector(readPreference), selectServerOptions ); - const skipPingOnConnect = this.s.options[Symbol.for('@@mdb.skipPingOnConnect')] === true; + const skipPingOnConnect = this.s.options.__skipPingOnConnect === true; if (!skipPingOnConnect && this.s.credentials) { await server.command(ns('admin.$cmd'), { ping: 1 }, { timeoutContext }); stateTransition(this, STATE_CONNECTED); diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.12.deadlock.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.12.deadlock.test.ts index d4fde19f682..ee833fcbd52 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.12.deadlock.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.12.deadlock.test.ts @@ -34,7 +34,7 @@ class CapturingMongoClient extends MongoClient { commandStartedEvents: Array = []; clientsCreated = 0; constructor(url: string, options: MongoClientOptions = {}) { - options = { ...options, monitorCommands: true, [Symbol.for('@@mdb.skipPingOnConnect')]: true }; + options = { ...options, monitorCommands: true, __skipPingOnConnect: true }; if (process.env.MONGODB_API_VERSION) { options.serverApi = process.env.MONGODB_API_VERSION as MongoClientOptions['serverApi']; } diff --git a/test/integration/command-logging-and-monitoring/command_logging_and_monitoring.prose.test.ts b/test/integration/command-logging-and-monitoring/command_logging_and_monitoring.prose.test.ts index 22857a6cc38..ea909408318 100644 --- a/test/integration/command-logging-and-monitoring/command_logging_and_monitoring.prose.test.ts +++ b/test/integration/command-logging-and-monitoring/command_logging_and_monitoring.prose.test.ts @@ -3,7 +3,6 @@ import { expect } from 'chai'; import { DEFAULT_MAX_DOCUMENT_LENGTH, type Document } from '../../mongodb'; describe('Command Logging and Monitoring Prose Tests', function () { - const loggerFeatureFlag = Symbol.for('@@mdb.enableMongoLogger'); const ELLIPSES_LENGTH = 3; let client; let writable; @@ -40,7 +39,7 @@ describe('Command Logging and Monitoring Prose Tests', function () { client = this.configuration.newClient( {}, { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogPath: writable, mongodbLogComponentSeverities: { command: 'debug' @@ -124,7 +123,7 @@ describe('Command Logging and Monitoring Prose Tests', function () { client = this.configuration.newClient( {}, { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogPath: writable, mongodbLogComponentSeverities: { command: 'debug' @@ -181,7 +180,7 @@ describe('Command Logging and Monitoring Prose Tests', function () { client = this.configuration.newClient( {}, { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogPath: writable, mongodbLogComponentSeverities: { command: 'debug' diff --git a/test/integration/node-specific/feature_flags.test.ts b/test/integration/node-specific/feature_flags.test.ts deleted file mode 100644 index 14981fdd7cf..00000000000 --- a/test/integration/node-specific/feature_flags.test.ts +++ /dev/null @@ -1,168 +0,0 @@ -import { expect } from 'chai'; - -import { MongoClient, SeverityLevel } from '../../mongodb'; - -describe('Feature Flags', () => { - describe('@@mdb.skipPingOnConnect', () => { - beforeEach(function () { - if (process.env.AUTH !== 'auth') { - this.currentTest.skipReason = 'ping count relies on auth to be enabled'; - this.skip(); - } - }); - - const tests = [ - // only skipInitiaPing=true will have no events upon connect - { description: 'should skip ping command when set to true', value: true, expectEvents: 0 }, - { - description: 'should not skip ping command when set to false', - value: false, - expectEvents: 1 - }, - { description: 'should not skip ping command when unset', value: undefined, expectEvents: 1 } - ]; - for (const { description, value, expectEvents } of tests) { - it(description, async function () { - const options = - value === undefined ? {} : { [Symbol.for('@@mdb.skipPingOnConnect')]: value }; - const client = this.configuration.newClient({}, { ...options, monitorCommands: true }); - const events = []; - client.on('commandStarted', event => events.push(event)); - - try { - await client.connect(); - } finally { - await client.close(); - } - - expect(events).to.have.lengthOf(expectEvents); - if (expectEvents > 1) { - for (const event of events) { - expect(event).to.have.property('commandName', 'ping'); - } - } - }); - } - }); - - // TODO(NODE-5672): Release Standardized Logger - describe('@@mdb.enableMongoLogger', () => { - let cachedEnv; - const loggerFeatureFlag = Symbol.for('@@mdb.enableMongoLogger'); - - before(() => { - cachedEnv = process.env; - }); - - after(() => { - process.env = cachedEnv; - }); - - context('when enabled', () => { - context('when logging is enabled for any component', () => { - before(() => { - process.env.MONGODB_LOG_COMMAND = SeverityLevel.EMERGENCY; - }); - - it('enables logging for the specified component', () => { - const client = new MongoClient('mongodb://localhost:27017', { - [loggerFeatureFlag]: true - }); - expect(client.mongoLogger?.componentSeverities).to.have.property( - 'command', - SeverityLevel.EMERGENCY - ); - }); - }); - - context('when logging is not enabled for any component', () => { - before(() => { - process.env = {}; - }); - - it('does not create logger', () => { - const client = new MongoClient('mongodb://localhost:27017', { - [loggerFeatureFlag]: true - }); - expect(client.mongoLogger).to.not.exist; - }); - }); - }); - - for (const featureFlagValue of [false, undefined]) { - context(`when set to ${featureFlagValue}`, () => { - context('when logging is enabled for a component', () => { - before(() => { - process.env['MONGODB_LOG_COMMAND'] = SeverityLevel.EMERGENCY; - }); - - it('does not instantiate logger', () => { - const client = new MongoClient('mongodb://localhost:27017', { - [loggerFeatureFlag]: featureFlagValue - }); - expect(client.mongoLogger).to.not.exist; - }); - }); - - context('when logging is not enabled for any component', () => { - before(() => { - process.env = {}; - }); - - it('does not instantiate logger', () => { - const client = new MongoClient('mongodb://localhost:27017', { - [loggerFeatureFlag]: featureFlagValue - }); - expect(client.mongoLogger).to.not.exist; - }); - }); - }); - } - }); - - describe('@@mdb.internalLoggerConfig', () => { - let cachedEnv: NodeJS.ProcessEnv; - - before(() => { - cachedEnv = process.env; - }); - - after(() => { - process.env = cachedEnv; - }); - - context('when undefined', function () { - before(() => { - process.env.MONGODB_LOG_COMMAND = SeverityLevel.EMERGENCY; - }); - - it('falls back to environment options', function () { - const client = new MongoClient('mongodb://localhost:27017', { - [Symbol.for('@@mdb.enableMongoLogger')]: true, - [Symbol.for('@@mdb.internalLoggerConfig')]: undefined - }); - - expect(client.mongoLogger?.componentSeverities).to.have.property( - 'command', - SeverityLevel.EMERGENCY - ); - }); - }); - - context('when defined', function () { - it('overrides environment options', function () { - const client = new MongoClient('mongodb://localhost:27017', { - [Symbol.for('@@mdb.enableMongoLogger')]: true, - [Symbol.for('@@mdb.internalLoggerConfig')]: { - MONGODB_LOG_COMMAND: SeverityLevel.ALERT - } - }); - - expect(client.mongoLogger?.componentSeverities).to.have.property( - 'command', - SeverityLevel.ALERT - ); - }); - }); - }); -}); diff --git a/test/integration/node-specific/ipv6.test.ts b/test/integration/node-specific/ipv6.test.ts index 2f48b0254b4..b030fdb210c 100644 --- a/test/integration/node-specific/ipv6.test.ts +++ b/test/integration/node-specific/ipv6.test.ts @@ -31,7 +31,7 @@ describe('IPv6 Addresses', () => { ipv6Hosts = this.configuration.options.hostAddresses.map(({ port }) => `[::1]:${port}`); client = this.configuration.newClient(`mongodb://${ipv6Hosts.join(',')}/test`, { - [Symbol.for('@@mdb.skipPingOnConnect')]: true, + __skipPingOnConnect: true, maxPoolSize: 1 }); }); diff --git a/test/integration/node-specific/mongo_client.test.ts b/test/integration/node-specific/mongo_client.test.ts index 634516f8f76..059d9d82c2d 100644 --- a/test/integration/node-specific/mongo_client.test.ts +++ b/test/integration/node-specific/mongo_client.test.ts @@ -15,6 +15,7 @@ import { MongoServerSelectionError, ReadPreference, ServerDescription, + SeverityLevel, Topology } from '../../mongodb'; import { runLater } from '../../tools/utils'; @@ -456,8 +457,8 @@ describe('class MongoClient', function () { const [findCommandStarted] = await findCommandToBeStarted; expect(findCommandStarted).to.have.property('commandName', 'find'); - expect(client.options).to.not.have.property(Symbol.for('@@mdb.skipPingOnConnect')); - expect(client.s.options).to.not.have.property(Symbol.for('@@mdb.skipPingOnConnect')); + expect(client.options).to.not.have.property('__skipPingOnConnect'); + expect(client.s.options).to.not.have.property('__skipPingOnConnect'); // Assertion is redundant but it shows that no initial ping is run expect(findCommandStarted.commandName).to.not.equal('ping'); @@ -475,8 +476,8 @@ describe('class MongoClient', function () { const [insertCommandStarted] = await insertOneCommandToBeStarted; expect(insertCommandStarted).to.have.property('commandName', 'insert'); - expect(client.options).to.not.have.property(Symbol.for('@@mdb.skipPingOnConnect')); - expect(client.s.options).to.not.have.property(Symbol.for('@@mdb.skipPingOnConnect')); + expect(client.options).to.not.have.property('__skipPingOnConnect'); + expect(client.s.options).to.not.have.property('__skipPingOnConnect'); // Assertion is redundant but it shows that no initial ping is run expect(insertCommandStarted.commandName).to.not.equal('ping'); @@ -774,4 +775,171 @@ describe('class MongoClient', function () { }); }); }); + + describe('internal options', function () { + describe('__skipPingOnConnect', () => { + beforeEach(function () { + if (process.env.AUTH !== 'auth') { + this.currentTest.skipReason = 'ping count relies on auth to be enabled'; + this.skip(); + } + }); + + const tests = [ + // only skipInitiaPing=true will have no events upon connect + { description: 'should skip ping command when set to true', value: true, expectEvents: 0 }, + { + description: 'should not skip ping command when set to false', + value: false, + expectEvents: 1 + }, + { + description: 'should not skip ping command when unset', + value: undefined, + expectEvents: 1 + } + ]; + for (const { description, value, expectEvents } of tests) { + it(description, async function () { + const options = value === undefined ? {} : { __skipPingOnConnect: value }; + const client = this.configuration.newClient({}, { ...options, monitorCommands: true }); + const events = []; + client.on('commandStarted', event => events.push(event)); + + try { + await client.connect(); + } finally { + await client.close(); + } + + expect(events).to.have.lengthOf(expectEvents); + if (expectEvents > 1) { + for (const event of events) { + expect(event).to.have.property('commandName', 'ping'); + } + } + }); + } + }); + + // TODO(NODE-5672): Release Standardized Logger + describe('__enableMongoLogger', () => { + let cachedEnv; + + before(() => { + cachedEnv = process.env; + }); + + after(() => { + process.env = cachedEnv; + }); + + context('when enabled', () => { + context('when logging is enabled for any component', () => { + before(() => { + process.env.MONGODB_LOG_COMMAND = SeverityLevel.EMERGENCY; + }); + + it('enables logging for the specified component', () => { + const client = new MongoClient('mongodb://localhost:27017', { + __enableMongoLogger: true + }); + expect(client.mongoLogger?.componentSeverities).to.have.property( + 'command', + SeverityLevel.EMERGENCY + ); + }); + }); + + context('when logging is not enabled for any component', () => { + before(() => { + process.env = {}; + }); + + it('does not create logger', () => { + const client = new MongoClient('mongodb://localhost:27017', { + __enableMongoLogger: true + }); + expect(client.mongoLogger).to.not.exist; + }); + }); + }); + + for (const optionValue of [false, undefined]) { + context(`when set to ${optionValue}`, () => { + context('when logging is enabled for a component', () => { + before(() => { + process.env['MONGODB_LOG_COMMAND'] = SeverityLevel.EMERGENCY; + }); + + it('does not instantiate logger', () => { + const client = new MongoClient('mongodb://localhost:27017', { + __enableMongoLogger: optionValue + }); + expect(client.mongoLogger).to.not.exist; + }); + }); + + context('when logging is not enabled for any component', () => { + before(() => { + process.env = {}; + }); + + it('does not instantiate logger', () => { + const client = new MongoClient('mongodb://localhost:27017', { + __enableMongoLogger: optionValue + }); + expect(client.mongoLogger).to.not.exist; + }); + }); + }); + } + }); + + describe('__internalLoggerConfig', () => { + let cachedEnv: NodeJS.ProcessEnv; + + before(() => { + cachedEnv = process.env; + }); + + after(() => { + process.env = cachedEnv; + }); + + context('when undefined', function () { + before(() => { + process.env.MONGODB_LOG_COMMAND = SeverityLevel.EMERGENCY; + }); + + it('falls back to environment options', function () { + const client = new MongoClient('mongodb://localhost:27017', { + __enableMongoLogger: true, + __internalLoggerConfig: undefined + }); + + expect(client.mongoLogger?.componentSeverities).to.have.property( + 'command', + SeverityLevel.EMERGENCY + ); + }); + }); + + context('when defined', function () { + it('overrides environment options', function () { + const client = new MongoClient('mongodb://localhost:27017', { + __enableMongoLogger: true, + __internalLoggerConfig: { + MONGODB_LOG_COMMAND: SeverityLevel.ALERT + } + }); + + expect(client.mongoLogger?.componentSeverities).to.have.property( + 'command', + SeverityLevel.ALERT + ); + }); + }); + }); + }); }); diff --git a/test/tools/spec-runner/index.js b/test/tools/spec-runner/index.js index 9e7cc01059b..42ea3b126b1 100644 --- a/test/tools/spec-runner/index.js +++ b/test/tools/spec-runner/index.js @@ -363,7 +363,7 @@ function runTestSuiteTest(configuration, spec, context) { minHeartbeatFrequencyMS: 100, monitorCommands: true, ...spec.clientOptions, - [Symbol.for('@@mdb.skipPingOnConnect')]: true + __skipPingOnConnect: true }); if (context.requiresCSFLE) { diff --git a/test/tools/unified-spec-runner/entities.ts b/test/tools/unified-spec-runner/entities.ts index 7f90e275dc8..04a6c6bc69c 100644 --- a/test/tools/unified-spec-runner/entities.ts +++ b/test/tools/unified-spec-runner/entities.ts @@ -222,9 +222,9 @@ export class UnifiedMongoClient extends MongoClient { super(uri, { monitorCommands: true, - [Symbol.for('@@mdb.skipPingOnConnect')]: true, - [Symbol.for('@@mdb.enableMongoLogger')]: true, - [Symbol.for('@@mdb.internalLoggerConfig')]: componentSeverities, + __skipPingOnConnect: true, + __enableMongoLogger: true, + __internalLoggerConfig: componentSeverities, ...getEnvironmentalOptions(), ...(description.serverApi ? { serverApi: description.serverApi } : {}), mongodbLogPath: logCollector, diff --git a/test/unit/connection_string.test.ts b/test/unit/connection_string.test.ts index 244273ef789..f4a9591e038 100644 --- a/test/unit/connection_string.test.ts +++ b/test/unit/connection_string.test.ts @@ -12,7 +12,6 @@ import { COSMOS_DB_MSG, DEFAULT_ALLOWED_HOSTS, DOCUMENT_DB_MSG, - FEATURE_FLAGS, type Log, MongoAPIError, MongoClient, @@ -748,43 +747,6 @@ describe('Connection String', function () { }); }); - describe('feature flags', () => { - it('should be stored in the FEATURE_FLAGS Set', () => { - expect(FEATURE_FLAGS.size).to.equal(3); - expect(FEATURE_FLAGS.has(Symbol.for('@@mdb.skipPingOnConnect'))).to.be.true; - expect(FEATURE_FLAGS.has(Symbol.for('@@mdb.enableMongoLogger'))).to.be.true; - expect(FEATURE_FLAGS.has(Symbol.for('@@mdb.internalLoggerConfig'))).to.be.true; - // Add more flags here - }); - - it('should should ignore unknown symbols', () => { - const randomFlag = Symbol(); - const client = new MongoClient('mongodb://iLoveJavaScript', { [randomFlag]: 23n }); - expect(client.s.options).to.not.have.property(randomFlag); - }); - - it('should be prefixed with @@mdb.', () => { - for (const flag of FEATURE_FLAGS) { - expect(flag).to.be.a('symbol'); - expect(flag).to.have.property('description'); - expect(flag.description).to.match(/@@mdb\..+/); - } - }); - - it('should only exist if specified on options', () => { - const flag = Array.from(FEATURE_FLAGS)[0]; // grab a random supported flag - const client = new MongoClient('mongodb://iLoveJavaScript', { [flag]: true }); - expect(client.s.options).to.have.property(flag, true); - expect(client.options).to.have.property(flag, true); - }); - - it('should support nullish values', () => { - const flag = Array.from(FEATURE_FLAGS.keys())[0]; // grab a random supported flag - const client = new MongoClient('mongodb://iLoveJavaScript', { [flag]: null }); - expect(client.s.options).to.have.property(flag, null); - }); - }); - describe('IPv6 host addresses', () => { it('should not allow multiple unbracketed portless localhost IPv6 addresses', () => { // Note there is no "port-full" version of this test, there's no way to distinguish when a port begins without brackets @@ -874,8 +836,6 @@ describe('Connection String', function () { }); describe('when mongodbLogPath is in options', function () { - const loggerFeatureFlag = Symbol.for('@@mdb.enableMongoLogger'); - let stderrStub; let stdoutStub; @@ -891,7 +851,7 @@ describe('Connection String', function () { context('when option is `stderr`', function () { it('it is accessible through mongoLogger.logDestination', function () { const client = new MongoClient('mongodb://a/?mongodbLogPath=stderr', { - [loggerFeatureFlag]: true + __enableMongoLogger: true }); const log: Log = { t: new Date(), c: 'ConnectionStringStdErr', s: 'error' }; client.options.mongoLoggerOptions.logDestination.write(log); @@ -903,7 +863,7 @@ describe('Connection String', function () { context('when option is `stdout`', function () { it('it is accessible through mongoLogger.logDestination', function () { const client = new MongoClient('mongodb://a/?mongodbLogPath=stdout', { - [loggerFeatureFlag]: true + __enableMongoLogger: true }); const log: Log = { t: new Date(), c: 'ConnectionStringStdOut', s: 'error' }; client.options.mongoLoggerOptions.logDestination.write(log); @@ -916,7 +876,7 @@ describe('Connection String', function () { it('should throw error at construction', function () { expect( () => - new MongoClient('mongodb://a/?mongodbLogPath=stdnothing', { [loggerFeatureFlag]: true }) + new MongoClient('mongodb://a/?mongodbLogPath=stdnothing', { __enableMongoLogger: true }) ).to.throw(MongoAPIError); }); }); @@ -931,7 +891,6 @@ describe('Connection String', function () { process.env.MONGODB_LOG_CLIENT = undefined; }); - const loggerFeatureFlag = Symbol.for('@@mdb.enableMongoLogger'); const test_cases = [ ['non-SRV example uri', 'mongodb://a.example.com:27017,b.example.com:27017/', ''], ['non-SRV default uri', 'mongodb://a.mongodb.net:27017', ''], @@ -960,7 +919,7 @@ describe('Connection String', function () { } }; new MongoClient(uri, { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogPath: stream }); diff --git a/test/unit/mongo_client.test.ts b/test/unit/mongo_client.test.ts index 194721350ac..2dcc9210278 100644 --- a/test/unit/mongo_client.test.ts +++ b/test/unit/mongo_client.test.ts @@ -829,8 +829,6 @@ describe('MongoClient', function () { }); describe('logging client options', function () { - const loggerFeatureFlag = Symbol.for('@@mdb.enableMongoLogger'); - describe('mongodbLogPath', function () { context('when mongodbLogPath is in options', function () { let stderrStub; @@ -848,7 +846,7 @@ describe('MongoClient', function () { context('when option is `stderr`', function () { it('it is accessible through mongoLogger.logDestination', function () { const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogPath: 'stderr' }); const log = { t: new Date(), c: 'constructorStdErr', s: 'error' }; @@ -867,7 +865,7 @@ describe('MongoClient', function () { } }; const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogPath: writable }); expect(client.options.mongoLoggerOptions.logDestination).to.deep.equal(writable); @@ -877,7 +875,7 @@ describe('MongoClient', function () { context('when option is `stdout`', function () { it('it is accessible through mongoLogger.logDestination', function () { const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogPath: 'stdout' }); const log = { t: new Date(), c: 'constructorStdOut', s: 'error' }; @@ -894,7 +892,7 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogPath: invalidOption }) ).to.throw(MongoAPIError); @@ -912,7 +910,7 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogPath: writable }) ).to.throw(MongoAPIError); @@ -934,7 +932,7 @@ describe('MongoClient', function () { it('should default to stderr', function () { const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true + __enableMongoLogger: true }); const log = { t: new Date(), c: 'constructorStdErr', s: 'error' }; client.options.mongoLoggerOptions.logDestination.write(log); @@ -958,7 +956,7 @@ describe('MongoClient', function () { it(`it stores severity levels for ${components[i]} component correctly`, function () { for (const severityLevel of Object.values(SeverityLevel)) { const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogComponentSeverities: { [components[i]]: severityLevel } @@ -982,7 +980,7 @@ describe('MongoClient', function () { process.env[env_component_names[i]] = 'emergency'; for (const severityLevel of Object.values(SeverityLevel)) { const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogComponentSeverities: { [components[i]]: severityLevel } @@ -1007,7 +1005,7 @@ describe('MongoClient', function () { for (const severityLevel of Object.values(SeverityLevel)) { for (const defaultSeverityLevel of Object.values(SeverityLevel)) { const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogComponentSeverities: { [components[i]]: severityLevel, default: defaultSeverityLevel @@ -1032,7 +1030,7 @@ describe('MongoClient', function () { context('when invalid client option is provided', function () { const badClientCreator = () => new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogComponentSeverities: { default: 'imFake' } @@ -1077,12 +1075,12 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogComponentSeverities: {} }) ).to.not.throw(MongoAPIError); const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogComponentSeverities: { client: 'error' } // dummy so logger doesn't turn on }); expect(client.mongoLogger?.componentSeverities.command).to.equal('off'); @@ -1093,12 +1091,12 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogComponentSeverities: { default: 'emergency' } }) ).to.not.throw(MongoAPIError); const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogComponentSeverities: { command: 'emergency' } }); expect(client.mongoLogger?.componentSeverities.command).to.equal('emergency'); @@ -1113,7 +1111,7 @@ describe('MongoClient', function () { context('when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is not provided', function () { it('should store value for maxDocumentLength correctly', function () { const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogMaxDocumentLength: 290 }); expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(290); @@ -1122,7 +1120,7 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogMaxDocumentLength: -290 }) ).to.throw(MongoParseError); @@ -1139,7 +1137,7 @@ describe('MongoClient', function () { it('should store value for maxDocumentLength correctly (client option value takes precedence)', function () { const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogMaxDocumentLength: 290 }); expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(290); @@ -1148,7 +1146,7 @@ describe('MongoClient', function () { expect( () => new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true, + __enableMongoLogger: true, mongodbLogMaxDocumentLength: -290 }) ).to.throw(MongoParseError); @@ -1159,7 +1157,7 @@ describe('MongoClient', function () { context('when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is not provided', function () { it('should store value for default maxDocumentLength correctly', function () { const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true + __enableMongoLogger: true }); expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(1000); }); @@ -1172,7 +1170,7 @@ describe('MongoClient', function () { it('should store value for maxDocumentLength correctly', function () { process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH = '155'; const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true + __enableMongoLogger: true }); expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(155); }); @@ -1180,7 +1178,7 @@ describe('MongoClient', function () { it('should not throw error for negative MONGODB_MAX_DOCUMENT_LENGTH and set to default', function () { process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH = '-14'; const client = new MongoClient('mongodb://a/', { - [loggerFeatureFlag]: true + __enableMongoLogger: true }); expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(1000); }); diff --git a/test/unit/sdam/server_selection.test.ts b/test/unit/sdam/server_selection.test.ts index e2c581dfb9e..b372178479f 100644 --- a/test/unit/sdam/server_selection.test.ts +++ b/test/unit/sdam/server_selection.test.ts @@ -610,7 +610,7 @@ describe('server selection', function () { }); }); - describe('server selection logging feature flagging', function () { + describe('willLog()', function () { let mockServer; let topology; let address;