From ade9a62301abfdb093fbbc2ff37c0a2e6776f977 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Thu, 27 Feb 2020 20:34:50 -0500 Subject: [PATCH] refactor: default to unified topology There is no longer any topology type other than the unified topology, so we default to it in the `connect` operation, and remove all tests that don't work with it. --- lib/core/sdam/common.js | 1 - lib/core/utils.js | 4 +- lib/mongo_client.js | 1 - lib/operations/connect.js | 131 +---- .../client_side_encryption/corpus.test.js | 14 +- .../client_side_encryption/driver.test.js | 3 +- .../client_side_encryption/prose.test.js | 35 +- test/functional/connection.test.js | 152 ------ test/functional/connections_stepdown.test.js | 5 +- test/functional/core/cursor.test.js | 126 ----- .../core/replset_server_selection.test.js | 152 ------ test/functional/core/server.test.js | 256 --------- .../core/single_mocks/timeout.test.js | 336 ------------ test/functional/cursor.test.js | 69 --- test/functional/db.test.js | 120 ----- test/functional/domain.test.js | 85 --- test/functional/find.test.js | 5 - test/functional/index.test.js | 42 -- test/functional/mongo_client.test.js | 505 ------------------ test/functional/mongo_client_options.test.js | 60 --- test/functional/operation_example.test.js | 62 --- .../operation_generators_example.test.js | 62 --- .../operation_promises_example.test.js | 61 --- test/functional/replicaset_mock.test.js | 29 - test/functional/sharding_connection.test.js | 162 ------ test/functional/spec-runner/context.js | 5 +- test/functional/spec-runner/index.js | 3 - test/functional/transactions.test.js | 6 +- test/functional/uri.test.js | 41 -- test/tools/atlas_connectivity_tests.js | 6 +- test/tools/runner/config.js | 14 +- test/tools/runner/index.js | 2 +- test/tools/sdam_viz | 13 +- test/unit/change_stream_resume.test.js | 5 +- test/unit/client.test.js | 1 - 35 files changed, 29 insertions(+), 2545 deletions(-) delete mode 100644 test/functional/core/replset_server_selection.test.js delete mode 100644 test/functional/core/single_mocks/timeout.test.js delete mode 100644 test/functional/sharding_connection.test.js diff --git a/lib/core/sdam/common.js b/lib/core/sdam/common.js index c99b01c569..a07b755834 100644 --- a/lib/core/sdam/common.js +++ b/lib/core/sdam/common.js @@ -29,7 +29,6 @@ const ServerType = { }; const TOPOLOGY_DEFAULTS = { - useUnifiedTopology: true, localThresholdMS: 15, serverSelectionTimeoutMS: 30000, heartbeatFrequencyMS: 10000, diff --git a/lib/core/utils.js b/lib/core/utils.js index ab778bf8db..f4a8222bf7 100644 --- a/lib/core/utils.js +++ b/lib/core/utils.js @@ -224,9 +224,7 @@ function makeClientMetadata(options) { architecture: process.arch, version: os.release() }, - platform: `'Node.js ${process.version}, ${os.endianness} (${ - options.useUnifiedTopology ? 'unified' : 'legacy' - })` + platform: `'Node.js ${process.version}, ${os.endianness} (unified)` }; // support optionally provided wrapping driver info diff --git a/lib/mongo_client.js b/lib/mongo_client.js index 4a0d88c914..30b99829e6 100644 --- a/lib/mongo_client.js +++ b/lib/mongo_client.js @@ -142,7 +142,6 @@ const validOptions = require('./operations/connect').validOptions; * @param {boolean} [options.monitorCommands=false] Enable command monitoring for this client * @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections * @param {boolean} [options.useNewUrlParser=true] Determines whether or not to use the new url parser. Enables the new, spec-compliant, url parser shipped in the core driver. This url parser fixes a number of problems with the original parser, and aims to outright replace that parser in the near future. Defaults to true, and must be explicitly set to false to use the legacy url parser. - * @param {boolean} [options.useUnifiedTopology] Enables the new unified topology layer * @param {AutoEncrypter~AutoEncryptionOptions} [options.autoEncryption] Optionally enable client side auto encryption * @param {DriverInfoOptions} [options.driverInfo] Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver * @param {MongoClient~connectCallback} [callback] The command result callback diff --git a/lib/operations/connect.js b/lib/operations/connect.js index 48078d207a..c671f34f31 100644 --- a/lib/operations/connect.js +++ b/lib/operations/connect.js @@ -17,14 +17,6 @@ const fs = require('fs'); const BSON = require('../core/connection/utils').retrieveBSON(); const CMAP_EVENT_NAMES = require('../cmap/events').CMAP_EVENT_NAMES; -let client; -function loadClient() { - if (!client) { - client = require('../mongo_client'); - } - return client; -} - const legacyParse = deprecate( require('../url_parser'), 'current URL string parser is deprecated, and will be removed in a future version. ' + @@ -41,30 +33,6 @@ const AUTH_MECHANISM_INTERNAL_MAP = { 'SCRAM-SHA-256': 'scram-sha-256' }; -const monitoringEvents = [ - 'timeout', - 'close', - 'serverOpening', - 'serverDescriptionChanged', - 'serverHeartbeatStarted', - 'serverHeartbeatSucceeded', - 'serverHeartbeatFailed', - 'serverClosed', - 'topologyOpening', - 'topologyClosed', - 'topologyDescriptionChanged', - 'commandStarted', - 'commandSucceeded', - 'commandFailed', - 'joined', - 'left', - 'ping', - 'ha', - 'all', - 'fullsetup', - 'open' -]; - const VALID_AUTH_MECHANISMS = new Set([ 'DEFAULT', 'PLAIN', @@ -137,7 +105,6 @@ const validOptionNames = [ 'retryWrites', 'retryReads', 'useNewUrlParser', - 'useUnifiedTopology', 'serverSelectionTimeoutMS', 'useRecoveryToken', 'autoEncryption', @@ -210,31 +177,6 @@ function assignTopology(client, topology) { } } -// Clear out all events -function clearAllEvents(topology) { - monitoringEvents.forEach(event => topology.removeAllListeners(event)); -} - -// Collect all events in order from SDAM -function collectEvents(mongoClient, topology) { - let MongoClient = loadClient(); - const collectedEvents = []; - - if (mongoClient instanceof MongoClient) { - monitoringEvents.forEach(event => { - topology.on(event, (object1, object2) => { - if (event === 'open') { - collectedEvents.push({ event: event, object1: mongoClient }); - } else { - collectedEvents.push({ event: event, object1: object1, object2: object2 }); - } - }); - }); - } - - return collectedEvents; -} - function resolveTLSOptions(options) { if (options.tls == null) { return; @@ -247,9 +189,6 @@ function resolveTLSOptions(options) { }); } -const emitDeprecationForNonUnifiedTopology = deprecate(() => {}, -'current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. ' + 'To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.'); - function connect(mongoClient, url, options, callback) { options = Object.assign({}, options); @@ -317,20 +256,7 @@ function connect(mongoClient, url, options, callback) { } } - if (_finalOptions.useUnifiedTopology) { - return createTopology(mongoClient, 'unified', _finalOptions, connectCallback); - } - - emitDeprecationForNonUnifiedTopology(); - - // Do we have a replicaset then skip discovery and go straight to connectivity - if (_finalOptions.replicaSet || _finalOptions.rs_name) { - return createTopology(mongoClient, 'replicaset', _finalOptions, connectCallback); - } else if (object.servers.length > 1) { - return createTopology(mongoClient, 'mongos', _finalOptions, connectCallback); - } else { - return createServer(mongoClient, _finalOptions, connectCallback); - } + return createTopology(mongoClient, 'unified', _finalOptions, connectCallback); }); function connectCallback(err, topology) { @@ -400,52 +326,6 @@ function createListener(mongoClient, event) { }; } -function createServer(mongoClient, options, callback) { - // Pass in the promise library - options.promiseLibrary = mongoClient.s.promiseLibrary; - - // Set default options - const servers = translateOptions(options); - - const server = servers[0]; - - // Propagate the events to the client - const collectedEvents = collectEvents(mongoClient, server); - - // Connect to topology - server.connect(options, (err, topology) => { - if (err) { - server.close(true); - return callback(err); - } - // Clear out all the collected event listeners - clearAllEvents(server); - - // Relay all the events - relayEvents(mongoClient, server); - // Add listeners - addListeners(mongoClient, server); - // Check if we are really speaking to a mongos - const ismaster = topology.lastIsMaster(); - - // Set the topology - assignTopology(mongoClient, topology); - - // Do we actually have a mongos - if (ismaster && ismaster.msg === 'isdbgrid') { - // Destroy the current connection - topology.close(); - // Create mongos connection instead - return createTopology(mongoClient, 'mongos', options, callback); - } - - // Fire all the events - replayEvents(mongoClient, collectedEvents); - // Otherwise callback - callback(err, topology); - }); -} - const DEPRECATED_UNIFIED_EVENTS = new Set([ 'reconnect', 'reconnectFailed', @@ -711,15 +591,6 @@ function relayEvents(mongoClient, topology) { }); } -// -// Replay any events due to single server connection switching to Mongos -// -function replayEvents(mongoClient, events) { - for (let i = 0; i < events.length; i++) { - mongoClient.emit(events[i].event, events[i].object1, events[i].object2); - } -} - function transformUrlOptions(_object) { let object = Object.assign({ servers: _object.hosts }, _object.options); for (let name in object) { diff --git a/test/functional/client_side_encryption/corpus.test.js b/test/functional/client_side_encryption/corpus.test.js index 46e65597c8..e4d075635d 100644 --- a/test/functional/client_side_encryption/corpus.test.js +++ b/test/functional/client_side_encryption/corpus.test.js @@ -128,10 +128,7 @@ describe('Client Side Encryption Corpus', function() { before(function() { // 1. Create a MongoClient without encryption enabled (referred to as ``client``). - client = this.configuration.newClient({ - useNewUrlParser: true, - useUnifiedTopology: true - }); + client = this.configuration.newClient(); return Promise.resolve() .then(() => client.connect()) @@ -192,14 +189,7 @@ describe('Client Side Encryption Corpus', function() { [dataNamespace]: corpusSchema }; } - clientEncrypted = this.configuration.newClient( - {}, - { - useNewUrlParser: true, - useUnifiedTopology: true, - autoEncryption - } - ); + clientEncrypted = this.configuration.newClient({}, { autoEncryption }); return clientEncrypted.connect().then(() => { clientEncryption = new mongodbClientEncryption.ClientEncryption(client, { diff --git a/test/functional/client_side_encryption/driver.test.js b/test/functional/client_side_encryption/driver.test.js index ff36cd1a41..dd30606da2 100644 --- a/test/functional/client_side_encryption/driver.test.js +++ b/test/functional/client_side_encryption/driver.test.js @@ -26,7 +26,7 @@ describe('Client Side Encryption Functional', function() { describe('BSON Options', function() { beforeEach(function() { - this.client = this.configuration.newClient({}, { useUnifiedTopology: true }); + this.client = this.configuration.newClient(); const noop = () => {}; function encryptSchema(keyId, bsonType) { @@ -77,7 +77,6 @@ describe('Client Side Encryption Functional', function() { this.encryptedClient = this.configuration.newClient( {}, { - useUnifiedTopology: true, autoEncryption: { keyVaultNamespace, kmsProviders diff --git a/test/functional/client_side_encryption/prose.test.js b/test/functional/client_side_encryption/prose.test.js index 5c5abfd67f..6907526fd7 100644 --- a/test/functional/client_side_encryption/prose.test.js +++ b/test/functional/client_side_encryption/prose.test.js @@ -38,10 +38,7 @@ describe('Client Side Encryption Prose Tests', function() { const mongodbClientEncryption = this.configuration.mongodbClientEncryption; // #. Create a MongoClient without encryption enabled (referred to as ``client``). Enable command monitoring to listen for command_started events. - this.client = this.configuration.newClient( - {}, - { useNewUrlParser: true, useUnifiedTopology: true, monitorCommands: true } - ); + this.client = this.configuration.newClient({}, { monitorCommands: true }); this.commandStartedEvents = new EventCollector(this.client, 'commandStarted', { exclude: ['ismaster'] @@ -105,8 +102,6 @@ describe('Client Side Encryption Prose Tests', function() { this.clientEncrypted = this.configuration.newClient( {}, { - useNewUrlParser: true, - useUnifiedTopology: true, autoEncryption: { keyVaultNamespace, kmsProviders: this.configuration.kmsProviders(null, localKey), @@ -316,10 +311,7 @@ describe('Client Side Encryption Prose Tests', function() { // "aws": { } // } // Configure with ``keyVaultNamespace`` set to ``admin.datakeys``, and a default MongoClient as the ``keyVaultClient``. - this.client = this.configuration.newClient( - {}, - { useNewUrlParser: true, useUnifiedTopology: true } - ); + this.client = this.configuration.newClient(); return this.client.connect().then(() => { const mongodbClientEncryption = this.configuration.mongodbClientEncryption; @@ -466,10 +458,7 @@ describe('Client Side Encryption Prose Tests', function() { // First, perform the setup. // #. Create a MongoClient without encryption enabled (referred to as ``client``). - this.client = this.configuration.newClient( - {}, - { useNewUrlParser: true, useUnifiedTopology: true } - ); + this.client = this.configuration.newClient(); return ( this.client @@ -501,8 +490,6 @@ describe('Client Side Encryption Prose Tests', function() { this.clientEncrypted = this.configuration.newClient( {}, { - useNewUrlParser: true, - useUnifiedTopology: true, monitorCommands: true, autoEncryption: { keyVaultNamespace, @@ -659,10 +646,7 @@ describe('Client Side Encryption Prose Tests', function() { // First, perform the setup. // #. Create a MongoClient without encryption enabled (referred to as ``client``). - this.client = this.configuration.newClient( - {}, - { useNewUrlParser: true, useUnifiedTopology: true } - ); + this.client = this.configuration.newClient(); return this.client .connect() @@ -685,8 +669,6 @@ describe('Client Side Encryption Prose Tests', function() { this.clientEncrypted = this.configuration.newClient( {}, { - useNewUrlParser: true, - useUnifiedTopology: true, autoEncryption: { keyVaultNamespace, kmsProviders: this.configuration.kmsProviders(null, localKey) @@ -737,10 +719,7 @@ describe('Client Side Encryption Prose Tests', function() { const externalSchema = loadExternal('external-schema.json'); beforeEach(function() { - this.client = this.configuration.newClient( - {}, - { useNewUrlParser: true, useUnifiedTopology: true } - ); + this.client = this.configuration.newClient(); // #. Create a MongoClient without encryption enabled (referred to as ``client``). return ( @@ -785,7 +764,7 @@ describe('Client Side Encryption Prose Tests', function() { // this.configuration.url('fake-user', 'fake-pwd'), // TODO: Do this properly {}, - { useNewUrlParser: true, useUnifiedTopology: true, monitorCommands: true } + { monitorCommands: true } ); this.commandStartedEvents = new EventCollector( @@ -822,8 +801,6 @@ describe('Client Side Encryption Prose Tests', function() { this.clientEncrypted = this.configuration.newClient( {}, { - useNewUrlParser: true, - useUnifiedTopology: true, autoEncryption: Object.assign({}, options, { schemaMap: { 'db.coll': externalSchema diff --git a/test/functional/connection.test.js b/test/functional/connection.test.js index 3b6084275c..aa0f7d3051 100644 --- a/test/functional/connection.test.js +++ b/test/functional/connection.test.js @@ -32,34 +32,6 @@ describe('Connection', function() { } }); - /** - * @ignore - */ - it('should correctly disable monitoring for single server connection', { - metadata: { requires: { topology: 'single' } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // skipped for direct legacy variable inspection - return this.skip(); - } - - var client = configuration.newClient( - { w: 1 }, - { poolSize: 1, host: '/tmp/mongodb-27017.sock', monitoring: false } - ); - - client.connect(function(err, client) { - test.equal(null, err); - test.equal(false, client.topology.s.coreTopology.s.monitoring); - - client.close(done); - }); - } - }); - /** * @ignore */ @@ -260,67 +232,6 @@ describe('Connection', function() { } }); - /** - * @ignore - */ - it('test connect server options', { - metadata: { requires: { topology: 'single' } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // skipped for direct legacy variable inspection - return this.skip(); - } - - const client = configuration.newClient(configuration.url(), { - auto_reconnect: true, - poolSize: 4 - }); - - client.connect( - connectionTester(configuration, 'testConnectServerOptions', function(client) { - test.ok(client.topology.poolSize >= 1); - test.equal(4, client.topology.s.coreTopology.s.pool.size); - test.equal(true, client.topology.autoReconnect); - client.close(done); - }) - ); - } - }); - - /** - * @ignore - */ - it('testConnectAllOptions', { - metadata: { requires: { topology: 'single' } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // skipped for direct legacy variable inspection - return this.skip(); - } - - const client = configuration.newClient(configuration.url(), { - auto_reconnect: true, - poolSize: 4, - native_parser: process.env['TEST_NATIVE'] != null - }); - - client.connect( - connectionTester(configuration, 'testConnectAllOptions', function(client) { - test.ok(client.topology.poolSize >= 1); - test.equal(4, client.topology.s.coreTopology.s.pool.size); - test.equal(true, client.topology.autoReconnect); - client.close(done); - }) - ); - } - }); - /** * @ignore */ @@ -454,67 +365,4 @@ describe('Connection', function() { done(); } }); - - /** - * @ignore - */ - it('should correctly reconnect and finish query operation', { - metadata: { requires: { topology: 'single', unifiedTopology: false } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // The unified topology deprecates autoReconnect, this test depends on the `reconnect` event - return this.skip(); - } - - var client = configuration.newClient({ w: 1 }, { poolSize: 1, auto_reconnect: true }); - client.connect(function(err, client) { - var db = client.db(configuration.db); - test.equal(null, err); - - db.collection('test_reconnect').insert({ a: 1 }, function(err) { - test.equal(null, err); - // Signal db reconnect - var dbReconnect = 0; - var dbClose = 0; - - db.on('reconnect', function() { - ++dbReconnect; - }); - - db.on('close', function() { - ++dbClose; - }); - - client.topology.once('reconnect', function() { - // Await reconnect and re-authentication - db.collection('test_reconnect').findOne(function(err, doc) { - test.equal(null, err); - test.equal(1, doc.a); - test.equal(1, dbReconnect); - test.equal(1, dbClose); - - // Attempt disconnect again - client.topology.connections()[0].destroy(); - - // Await reconnect and re-authentication - db.collection('test_reconnect').findOne(function(err, doc) { - test.equal(null, err); - test.equal(1, doc.a); - test.equal(2, dbReconnect); - test.equal(2, dbClose); - - client.close(done); - }); - }); - }); - - // Force close - client.topology.connections()[0].destroy(); - }); - }); - } - }); }); diff --git a/test/functional/connections_stepdown.test.js b/test/functional/connections_stepdown.test.js index d63ecada68..ddd65bc8de 100644 --- a/test/functional/connections_stepdown.test.js +++ b/test/functional/connections_stepdown.test.js @@ -30,10 +30,7 @@ describe('Connections survive primary step down', function() { let collection; beforeEach(function() { - client = this.configuration.newClient( - { w: 1 }, - { poolSize: 1, retryWrites: false, useUnifiedTopology: true } - ); + client = this.configuration.newClient({ w: 1 }, { poolSize: 1, retryWrites: false }); return client .connect() diff --git a/test/functional/core/cursor.test.js b/test/functional/core/cursor.test.js index 3104607431..32307b09c4 100644 --- a/test/functional/core/cursor.test.js +++ b/test/functional/core/cursor.test.js @@ -336,132 +336,6 @@ describe('Cursor tests', function() { } }); - it('Should finish cursor correctly after all sockets to pool destroyed', { - metadata: { requires: { topology: ['single'] } }, - test: function(done) { - if (this.configuration.usingUnifiedTopology()) { - // This test tries to inspect the connection pool directly on the topology, which - // will no longer work with the new Topology type. The test should be reworked. - return this.skip(); - } - - const server = this.configuration.newTopology(); - var ns = f('%s.cursor6', this.configuration.db); - // Add event listeners - server.on('connect', function(_server) { - // Execute the write - _server.insert( - ns, - [{ a: 1 }, { a: 2 }, { a: 3 }], - { - writeConcern: { w: 1 }, - ordered: true - }, - function(err, results) { - expect(err).to.be.null; - expect(results.result.n).to.equal(3); - - // Execute find - var cursor = _server.cursor(ns, { find: ns, query: {}, batchSize: 2 }); - - // Execute next - cursor._next(function(nextCursorErr, nextCursorD) { - expect(nextCursorErr).to.be.null; - expect(nextCursorD.a).to.equal(1); - - // Get the next item - cursor._next(function(secondCursorErr, secondCursorD) { - expect(secondCursorErr).to.be.null; - expect(secondCursorD.a).to.equal(2); - - // Should be able to continue cursor after reconnect - _server.once('reconnect', function() { - cursor._next(function(thirdCursorErr, thirdCursorD) { - expect(thirdCursorErr).to.be.null; - expect(thirdCursorD.a).to.equal(3); - - // Destroy the server connection - _server.destroy(done); - }); - }); - - // Destroy all active connections in the pool - var connections = _server.s.pool.allConnections(); - for (var i = 0; i < connections.length; i++) { - connections[i].write('!@#!@#SADASDSA!@#!@#!@#!@#!@'); - } - }); - }); - } - ); - }); - - // Start connection - server.connect(); - } - }); - - it('Should not leak connnection workItem elements when using killCursor', { - metadata: { - requires: { topology: ['single'] } - }, - - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // This test tries to inspect the connection pool directly on the topology, which - // will no longer work with the new Topology type. The test should be reworked. - return this.skip(); - } - - const server = this.configuration.newTopology(); - var ns = f('%s.cursor4', this.configuration.db); - // Add event listeners - server.on('connect', function(_server) { - // Execute the write - _server.insert( - ns, - [{ a: 1 }, { a: 2 }, { a: 3 }], - { - writeConcern: { w: 1 }, - ordered: true - }, - function(err, results) { - expect(err).to.be.null; - expect(results.result.n).to.equal(3); - - // Execute find - var cursor = _server.cursor(ns, { find: ns, query: {}, batchSize: 2 }); - - // Execute next - cursor._next(function(nextCursorErr, nextCursorD) { - expect(nextCursorErr).to.be.null; - expect(nextCursorD.a).to.equal(1); - - // Kill cursor - cursor.kill(function() { - // Add a small delay so that the work can be queued after the kill - // callback has executed - setImmediate(function() { - var connections = _server.s.pool.allConnections(); - for (var i = 0; i < connections.length; i++) { - expect(connections[i].workItems.length).to.equal(0); - } - - // Destroy the server connection - _server.destroy(done); - }, 100); - }); - }); - } - ); - }); - - // Start connection - server.connect(); - } - }); - // NOTE: a notoriously flakey test, needs rewriting // Commented out to stop before task from running and breaking auth tests // it.skip('should not hang if autoReconnect=false and pools sockets all timed out', { diff --git a/test/functional/core/replset_server_selection.test.js b/test/functional/core/replset_server_selection.test.js deleted file mode 100644 index 1fbd2fb2bd..0000000000 --- a/test/functional/core/replset_server_selection.test.js +++ /dev/null @@ -1,152 +0,0 @@ -'use strict'; - -var expect = require('chai').expect, - fs = require('fs'), - p = require('path'), - ReplSetState = require('../../../lib/core/topologies/replset_state'), - MongoError = require('../../../lib/core/error').MongoError, - ReadPreference = require('../../../lib/core/topologies/read_preference'); - -describe('A replicaset with no primary', function() { - before(function() { - // These tests are not relevant to the new topology layer - if (this.configuration.usingUnifiedTopology()) this.skip(); - }); - - it('should correctly execute server selection tests', { - metadata: { requires: { topology: 'single' } }, - - test: function(done) { - const config = this.configuration; - var path = p.resolve( - __dirname, - '../../spec/server-selection/server_selection/ReplicaSetNoPrimary/read' - ); - var entries = fs.readdirSync(path).filter(function(x) { - return x.indexOf('.json') !== -1; - }); - - // Execute each of the entries - entries.forEach(function(x) { - executeEntry(config, x, `${path}/${x}`); - }); - - done(); - } - }); -}); - -describe('A replicaset with a primary', function() { - before(function() { - // These tests are not relevant to the new topology layer - if (this.configuration.usingUnifiedTopology()) this.skip(); - }); - - it('should correctly execute server selection tests', { - metadata: { requires: { topology: 'single' } }, - - test: function(done) { - const config = this.configuration; - var path = p.resolve( - __dirname, - '../../spec/server-selection/server_selection/ReplicaSetWithPrimary/read' - ); - - var entries = fs.readdirSync(path).filter(function(x) { - return x.indexOf('.json') !== -1; - }); - - // Execute each of the entries - entries.forEach(function(x) { - executeEntry(config, x, `${path}/${x}`); - }); - - done(); - } - }); -}); - -function convert(mode) { - if (mode.toLowerCase() === 'primarypreferred') return 'primaryPreferred'; - if (mode.toLowerCase() === 'secondarypreferred') return 'secondaryPreferred'; - return mode.toLowerCase(); -} - -function executeEntry(config, file, path) { - // Read and parse the json file - file = require(path); - - // Let's pick out the parts of the selection specification - var topologyDescription = file.topology_description; - var inLatencyWindow = file.in_latency_window; - var readPreference = file.read_preference; - - try { - // Create a Replset and populate it with dummy topology servers - var replset = new ReplSetState(); - replset.topologyType = topologyDescription.type; - // For each server add them to the state - topologyDescription.servers.forEach(function(s) { - var server = config.newTopology( - s.address.split(':')[0], - parseInt(s.address.split(':')[1], 10) - ); - - // Add additional information - if (s.avg_rtt_ms) server.lastIsMasterMS = s.avg_rtt_ms; - if (s.tags) server.ismaster = { tags: s.tags }; - // Ensure the server looks connected - server.isConnected = function() { - return true; - }; - - if (s.type === 'RSSecondary') { - replset.secondaries.push(server); - } else if (s.type === 'RSPrimary') { - replset.primary = server; - } else if (s.type === 'RSArbiter') { - replset.arbiters.push(server); - } - }); - - // Create read preference - let rp; - if (convert(readPreference.mode) !== 'primary' && readPreference.tag_sets) { - rp = new ReadPreference(convert(readPreference.mode), readPreference.tag_sets); - } else { - rp = new ReadPreference(convert(readPreference.mode)); - } - - // Perform a pickServer - var server = replset.pickServer(rp); - var foundWindow = null; - - // server should be in the latency window - for (var i = 0; i < inLatencyWindow.length; i++) { - var w = inLatencyWindow[i]; - - if (server.name === w.address) { - foundWindow = w; - break; - } - } - - if ( - ['ReplicaSetNoPrimary', 'Primary', 'ReplicaSetWithPrimary'].indexOf( - topologyDescription.type - ) !== -1 && - inLatencyWindow.length === 0 - ) { - if (server instanceof MongoError) { - expect(server.message).to.equal('no primary server available'); - } else { - expect(server).to.be.null; - } - } else { - expect(foundWindow).to.not.be.null; - } - } catch (err) { - console.log(err.stack); - process.exit(0); - } -} diff --git a/test/functional/core/server.test.js b/test/functional/core/server.test.js index c758ad4279..aef0dc2696 100644 --- a/test/functional/core/server.test.js +++ b/test/functional/core/server.test.js @@ -403,147 +403,6 @@ describe('Server tests', function() { } }); - it('should correctly reconnect to server with automatic reconnect enabled', { - metadata: { requires: { topology: 'single' } }, - test: function(done) { - const config = this.configuration; - if (config.usingUnifiedTopology()) { - // The new SDAM layer always reconnects, so this test is no longer relevant - return this.skip(); - } - - var server = config.newTopology(this.configuration.host, this.configuration.port, { - reconnect: true, - size: 1, - reconnectInterval: 50 - }); - - // Test flags - var emittedClose = false; - - // Add event listeners - server.on('connect', function(_server) { - // Execute the command - _server.command( - 'system.$cmd', - { ismaster: true }, - { readPreference: new ReadPreference('primary') }, - function(err, result) { - expect(err).to.be.null; - _server.s.currentReconnectRetry = 10; - - // Write garbage, force socket closure - try { - var a = Buffer.alloc(100); - for (var i = 0; i < 100; i++) a[i] = i; - result.connection.write(a); - } catch (loopErr) { - console.log(loopErr); - } - - // Ensure the server died - setTimeout(function() { - // Attempt a proper command - _server.command( - 'system.$cmd', - { ismaster: true }, - { readPreference: new ReadPreference('primary') }, - function(cmdErr) { - expect(cmdErr).to.not.be.null; - } - ); - }, 100); - } - ); - }); - - server.once('close', function() { - emittedClose = true; - }); - - server.once('reconnect', function() { - expect(emittedClose).to.be.true; - expect(server.isConnected()).to.be.true; - expect(server.s.pool.retriesLeft).to.equal(30); - server.destroy(); - done(); - }); - - // Start connection - server.connect(); - } - }); - - it('should correctly reconnect to server with automatic reconnect disabled', { - metadata: { - requires: { - topology: 'single' - } - // ignore: { travis:true } - }, - - test: function(done) { - const config = this.configuration; - if (config.usingUnifiedTopology()) { - // The new SDAM layer always reconnects, so this test is no longer relevant - return this.skip(); - } - - var server = config.newTopology(this.configuration.host, this.configuration.port, { - reconnect: false, - size: 1 - }); - - // Test flags - var emittedClose = false; - - // Add event listeners - server.on('connect', function(_server) { - // Execute the command - _server.command( - 'system.$cmd', - { ismaster: true }, - { readPreference: new ReadPreference('primary') }, - function(err, result) { - expect(err).to.be.null; - // Write garbage, force socket closure - try { - result.connection.destroy(); - } catch (destroyErr) { - console.log(destroyErr); - } - - process.nextTick(function() { - // Attempt a proper command - _server.command( - 'system.$cmd', - { ismaster: true }, - { readPreference: new ReadPreference('primary') }, - function(cmdErr) { - expect(cmdErr).to.not.be.null; - } - ); - }); - } - ); - }); - - server.on('close', function() { - emittedClose = true; - }); - - setTimeout(function() { - expect(emittedClose).to.be.true; - expect(server.isConnected()).to.be.false; - server.destroy(); - done(); - }, 500); - - // Start connection - server.connect(); - } - }); - it('should reconnect when initial connection failed', { metadata: { requires: { @@ -586,72 +445,6 @@ describe('Server tests', function() { } }); - it('should correctly place new connections in available list on reconnect', { - metadata: { requires: { topology: 'single' } }, - test: function(done) { - const config = this.configuration; - if (config.usingUnifiedTopology()) { - // The new SDAM layer always reconnects, so this test is no longer relevant - return this.skip(); - } - - var server = config.newTopology(this.configuration.host, this.configuration.port, { - reconnect: true, - size: 1, - reconnectInterval: 50 - }); - - // Add event listeners - server.on('connect', function(_server) { - // Execute the command - _server.command( - 'system.$cmd', - { ismaster: true }, - { readPreference: new ReadPreference('primary') }, - function(err, result) { - expect(err).to.be.null; - _server.s.currentReconnectRetry = 10; - - // Write garbage, force socket closure - try { - var a = Buffer.alloc(100); - for (var i = 0; i < 100; i++) a[i] = i; - result.connection.write(a); - } catch (garbageErr) { - console.log(garbageErr); - } - } - ); - }); - - server.once('reconnect', function() { - for (var i = 0; i < 100; i++) { - server.command('system.$cmd', { ismaster: true }, function(err, result) { - expect(err).to.be.null; - expect(result).to.exist; - }); - } - - server.command('system.$cmd', { ismaster: true }, function(err, result) { - expect(err).to.be.null; - expect(result).to.exist; - - setTimeout(function() { - expect(server.s.pool.availableConnections.length).to.be.above(0); - expect(server.s.pool.inUseConnections.length).to.equal(0); - expect(server.s.pool.connectingConnections).to.equal(0); - - server.destroy(); - done(); - }, 1000); - }); - }); - - // Start connection - server.connect(); - } - }); - it('should not overflow the poolSize due to concurrent operations', { metadata: { requires: { @@ -931,55 +724,6 @@ describe('Server tests', function() { } ); - it( - 'should correctly connect server to single instance and execute insert with snappy compression', - { - metadata: { requires: { topology: ['single'], mongodb: '>=3.5.x' } }, - - test: function(done) { - const config = this.configuration; - if (config.usingUnifiedTopology()) { - // Disabled for inspection of properties only relevant to legacy topology - return this.skip(); - } - - var server = config.newTopology(this.configuration.host, this.configuration.port, { - bson: new Bson(), - compression: { - compressors: ['snappy', 'zlib'] - } - }); - - // Add event listeners - server.on('connect', function() { - // Check compression has been negotiated - expect(server.s.pool.options.agreedCompressor).to.equal('snappy'); - - server.insert('integration_tests.inserts', { a: 1 }, function(insertOneErr, insertOneR) { - expect(insertOneErr).to.be.null; - expect(insertOneR.result.n).to.equal(1); - expect(insertOneR.message.fromCompressed).to.be.true; - - server.insert('integration_tests.inserts', { a: 2 }, { ordered: false }, function( - err, - r - ) { - expect(err).to.be.null; - expect(r.result.n).to.equal(1); - expect(r.message.fromCompressed).to.be.true; - - server.destroy(); - done(); - }); - }); - }); - - // Start connection - server.connect(); - } - } - ); - describe('Unsupported wire protocols', function() { let server; beforeEach(() => mock.createServer().then(_server => (server = _server))); diff --git a/test/functional/core/single_mocks/timeout.test.js b/test/functional/core/single_mocks/timeout.test.js deleted file mode 100644 index 1757272328..0000000000 --- a/test/functional/core/single_mocks/timeout.test.js +++ /dev/null @@ -1,336 +0,0 @@ -'use strict'; -var expect = require('chai').expect, - co = require('co'), - mock = require('mongodb-mock-server'); - -describe('Single Timeout (mocks)', function() { - before(function() { - if (this.configuration.usingUnifiedTopology()) { - // The new SDAM layer always reconnects, so these tests are no longer relevant. - return this.skip(); - } - }); - - afterEach(() => mock.cleanup()); - - it('Should correctly timeout socket operation and then correctly re-execute', { - metadata: { - requires: { - generators: true, - topology: 'single' - } - }, - - test: function(done) { - const config = this.configuration; - - // Current index for the ismaster - var currentStep = 0; - // Primary stop responding - var stopRespondingPrimary = false; - - // Default message fields - var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER); - - // Primary server states - var serverIsMaster = [Object.assign({}, defaultFields)]; - - // Boot the mock - co(function*() { - const server = yield mock.createServer(); - - server.setMessageHandler(request => { - var doc = request.document; - if (doc.ismaster && currentStep === 0) { - request.reply(serverIsMaster[0]); - currentStep += 1; - } else if (doc.insert && currentStep === 1) { - // Stop responding to any calls (emulate dropping packets on the floor) - if (stopRespondingPrimary) { - // yield timeoutPromise(3000); - // continue; - return; - } - - currentStep += 1; - } else if (doc.ismaster && currentStep === 2) { - request.reply(serverIsMaster[0]); - } else if (doc.insert && currentStep === 2) { - request.reply({ ok: 1, n: doc.documents, lastOp: new Date() }); - } - }); - - // Start dropping the packets - setTimeout(function() { - stopRespondingPrimary = true; - }, 5000); - - var replset = config.newTopology(server.address().host, server.address().port, { - connectionTimeout: 5000, - socketTimeout: 1000, - size: 1 - }); - - // Not done - var finished = false; - - // Add event listeners - replset.once('connect', function(_server) { - _server.insert('test.test', [{ created: new Date() }], function(err, r) { - expect(r).to.not.exist; - expect(err).to.exist; - - function wait() { - setTimeout(function() { - _server.insert('test.test', [{ created: new Date() }], function(_err, _r) { - if (_r && !finished) { - finished = true; - expect(_r.connection.port).to.equal(server.address().port); - replset.destroy({ force: true }); - done(); - } else { - wait(); - } - }); - }, 500); - } - - wait(); - }); - }); - - replset.on('error', done); - replset.connect(); - }); - } - }); - - it('Should correctly recover from an immediate shutdown mid insert', { - metadata: { - requires: { - generators: true, - topology: 'single' - } - }, - - test: function(done) { - const config = this.configuration; - - // Current index for the ismaster - var currentStep = 0; - // Should fail due to broken pipe - var brokenPipe = false; - - // Default message fields - var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER); - - // Primary server states - var serverIsMaster = [Object.assign({}, defaultFields)]; - - co(function*() { - const mockServer = yield mock.createServer(0, 'localhost', { - onRead: function(_server, connection) { - // Force EPIPE error - if (currentStep === 1) { - // Destroy connection mid write - connection.destroy(); - // Reset the mock to accept ismasters - setTimeout(function() { - currentStep += 1; - }, 10); - // Return connection was destroyed - return true; - } - } - }); - - mockServer.setMessageHandler(request => { - var doc = request.document; - if (doc.ismaster && currentStep === 0) { - currentStep += 1; - request.reply(serverIsMaster[0]); - } else if (doc.insert && currentStep === 2) { - currentStep += 1; - request.reply({ ok: 1, n: doc.documents, lastOp: new Date() }); - } else if (doc.ismaster) { - request.reply(serverIsMaster[0]); - } - }); - - var server = config.newTopology(mockServer.address().host, mockServer.address().port, { - connectionTimeout: 3000, - socketTimeout: 2000, - size: 1 - }); - - var docs = []; - // Create big insert message - for (var i = 0; i < 1000; i++) { - docs.push({ - a: i, - string: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string1: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string2: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string3: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string4: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string5: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string6: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string7: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string8: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string9: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string10: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string11: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string12: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string13: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string14: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string15: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string16: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string17: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string18: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string19: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string20: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string21: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string22: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string23: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string24: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string25: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string26: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string27: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world', - string28: - 'hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world' - }); - } - - // Add event listeners - server.once('connect', function(_server) { - _server.insert('test.test', docs, function(err, r) { - expect(r).to.not.exist; - expect(err).to.exist; - brokenPipe = true; - }); - }); - - server.once('reconnect', function(_server) { - _server.insert('test.test', [{ created: new Date() }], function(err, r) { - expect(r).to.exist; - expect(brokenPipe).to.equal(true); - server.destroy(); - done(); - }); - }); - - server.on('error', done); - setTimeout(function() { - server.connect(); - }, 100); - }); - } - }); - - it.skip( - 'Should not start double reconnect timeouts due to socket timeout during attemptReconnect', - { - metadata: { - requires: { - generators: true, - topology: 'single' - } - }, - - test: function(done) { - const config = this.configuration; - - // Current index for the ismaster - var currentStep = 0; - - // Default message fields - var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER); - - // Primary server states - var serverIsMaster = [Object.assign({}, defaultFields)]; - - // Boot the mock - co(function*() { - const mockServer = yield mock.createServer(); - - mockServer.setMessageHandler(request => { - if (currentStep === 1) { - // yield timeoutPromise(5000); - // continue; - return; - } - - var doc = request.document; - if (doc.ismaster && currentStep === 0) { - request.reply(serverIsMaster[0]); - currentStep += 1; - } - }); - - var server = config.newTopology(mockServer.address().host, mockServer.address().port, { - connectionTimeout: 2000, - socketTimeout: 1000, - size: 1 - }); - - // Add event listeners - server.once('connect', function() { - // _server.insert('test.test', [{created:new Date()}], function(err, r) { - // test.ok(err != null); - // // console.dir(err) - // - // function wait() { - // setTimeout(function() { - // _server.insert('test.test', [{created:new Date()}], function(err, r) { - // if (r && !done) { - // done = true; - // test.equal(37019, r.connection.port); - // replset.destroy(); - // running = false; - // test.done(); - // } else { - // wait(); - // } - // }); - // }, 500); - // } - // - // wait(); - // }); - }); - - server.on('error', done); - server.connect(); - }); - } - } - ); -}); diff --git a/test/functional/cursor.test.js b/test/functional/cursor.test.js index 1006e442bb..9fc0133f3f 100644 --- a/test/functional/cursor.test.js +++ b/test/functional/cursor.test.js @@ -2139,75 +2139,6 @@ describe('Cursor', function() { } }); - /** - * @ignore - * @api private - */ - it('cursor stream errors connection force closed', { - // Add a tag that our runner can trigger on - // in this case we are setting that node needs to be higher than 0.10.X to run - metadata: { - requires: { - mongodb: '<=3.5.0', // NOTE: remove this when SERVER-30576 is resolved - topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'], - unifiedTopology: false - } - }, - - // The actual test we wish to run - test: function(done) { - var configuration = this.configuration; - var client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 }); - client.connect(function(err, client) { - var db = client.db(configuration.db); - test.equal(null, err); - - db.createCollection('cursor_stream_errors', function(err, collection) { - test.equal(null, err); - - var docs = []; - for (var ii = 0; ii < 10; ++ii) docs.push({ b: ii + 1 }); - - // insert all docs - collection.insert(docs, configuration.writeConcernMax(), function(err) { - test.equal(null, err); - - var finished = 0, - i = 0; - - var stream = collection.find({}, { batchSize: 5 }).stream(); - - stream.on('data', function() { - if (++i === 5) { - client.topology - .connections()[0] - .write(Buffer.from('312312321321askdjljsaNCKnablibh')); - } - }); - - stream.once('close', testDone('close')); - stream.once('error', testDone('error')); - - function testDone() { - return function() { - ++finished; - - if (finished === 2) { - setTimeout(function() { - test.equal(5, i); - test.equal(2, finished); - test.equal(true, stream.isClosed()); - client.close(true, done); - }, 150); - } - }; - } - }); - }); - }); - } - }); - /** * @ignore * @api private diff --git a/test/functional/db.test.js b/test/functional/db.test.js index b9503f3503..7d6807502d 100644 --- a/test/functional/db.test.js +++ b/test/functional/db.test.js @@ -145,89 +145,6 @@ describe('Db', function() { } }); - /** - * @ignore - */ - it('shouldCorrectlyPerformAutomaticConnect', { - metadata: { requires: { topology: 'single' } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // The unified topology deprecates autoReconnect - return this.skip(); - } - - var client = configuration.newClient(configuration.writeConcernMax(), { - poolSize: 1, - auto_reconnect: true - }); - - client.connect(function(err, client) { - var automatic_connect_client = client.db(configuration.db); - - var closeListener = function() { - var collection = automatic_connect_client.collection('test_object_id_generation_data2'); - collection.insert({ name: 'Patty', age: 34 }, configuration.writeConcernMax(), function( - err, - r - ) { - test.equal(1, r.ops.length); - test.ok(r.ops[0]._id.toHexString().length === 24); - - collection.findOne({ name: 'Patty' }, function(err, document) { - test.equal(r.ops[0]._id.toHexString(), document._id.toHexString()); - client.close(done); - }); - }); - }; - - automatic_connect_client.once('close', closeListener); - automatic_connect_client.serverConfig.connections()[0].destroy(); - }); - } - }); - - /** - * @ignore - */ - it.skip('shouldCorrectlyPerformAutomaticConnectWithMaxBufferSize0', { - metadata: { requires: { topology: 'single' } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // The unified topology does not use a store - return this.skip(); - } - - var client = configuration.newClient( - { w: 1 }, - { poolSize: 1, auto_reconnect: true, bufferMaxEntries: 0 } - ); - - client.connect(function(err, client) { - var automatic_connect_client = client.db(configuration.db); - - var closeListener = function() { - var collection = automatic_connect_client.collection('test_object_id_generation_data2'); - collection.insert({ name: 'Patty', age: 34 }, configuration.writeConcernMax(), function( - err - ) { - test.ok(err != null); - test.ok(err.message.indexOf('0') !== -1); - client.close(done); - }); - }; - - automatic_connect_client.once('close', closeListener); - automatic_connect_client.serverConfig.connections()[0].destroy(); - }); - } - }); - /** * @ignore */ @@ -659,41 +576,4 @@ describe('Db', function() { }); } }); - - /** - * @ignore - */ - it('should correctly execute close function in order', { - metadata: { - requires: { - topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'], - mongodb: '>= 2.8.0', - unifiedTopology: false - } - }, - - // The actual test we wish to run - test: function(done) { - var configuration = this.configuration; - var client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 }); - - client.connect(function(err, client) { - expect(err).to.not.exist; - - // run one command to ensure connections exist, otherwise `close` is near immediate - client.db('admin').command({ ping: 1 }, err => { - expect(err).to.not.exist; - - var items = []; - items.push(1); - client.close(function() { - expect(items).to.have.length(2); - done(); - }); - - items.push(2); - }); - }); - } - }); }); diff --git a/test/functional/domain.test.js b/test/functional/domain.test.js index 21330c66ce..0f766a4fd5 100644 --- a/test/functional/domain.test.js +++ b/test/functional/domain.test.js @@ -105,89 +105,4 @@ describe('Domains', function() { }); } }); - - /** - * @ignore - */ - it('shouldStayInCorrectDomainForQueuedReadCommand', { - metadata: { - requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } - }, - - // The actual test we wish to run - test: function(done) { - var Domain = require('domain'); - var domainInstance = Domain.create(); - var configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // The unified topology does not use a store - return this.skip(); - } - - var client = configuration.newClient( - { w: 0 }, - { poolSize: 1, auto_reconnect: true, domainsEnabled: true, bufferMaxEntries: 0 } - ); - - client.connect(function(err, client) { - var db = client.db(configuration.db); - var connection = client.topology.connections()[0]; - var collection = db.collection('test'); - connection.destroy(); - - domainInstance.run(function() { - collection.count({}, function(err) { - test.ok(err != null); - test.ok(process.domain === domainInstance); - domainInstance.exit(); - client.close(true, done); - }); - }); - }); - } - }); - - /** - * @ignore - */ - it('shouldStayInCorrectDomainForQueuedWriteCommand', { - metadata: { - requires: { - topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] - } - }, - - // The actual test we wish to run - test: function(done) { - var Domain = require('domain'); - var domainInstance = Domain.create(); - var configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // The unified topology does not use a store - return this.skip(); - } - - var client = configuration.newClient( - { w: 1 }, - { poolSize: 1, auto_reconnect: true, domainsEnabled: true, bufferMaxEntries: 0 } - ); - - client.connect(function(err, client) { - test.ok(!err); - var db = client.db(configuration.db); - var connection = client.topology.connections()[0]; - var collection = db.collection('test'); - connection.destroy(); - - domainInstance.run(function() { - collection.insert({ field: 123 }, function(err) { - test.ok(err != null); - test.ok(process.domain === domainInstance); - domainInstance.exit(); - client.close(true, done); - }); - }); - }); - } - }); }); diff --git a/test/functional/find.test.js b/test/functional/find.test.js index 86ef96d9bb..7325fac799 100644 --- a/test/functional/find.test.js +++ b/test/functional/find.test.js @@ -3095,11 +3095,6 @@ describe('Find', function() { const config = this.configuration; const client = config.newClient({}, { monitorCommands: true, readPreference: 'secondary' }); - if (!config.usingUnifiedTopology()) { - this.skip(); - return; - } - client.connect((err, client) => { expect(err).to.not.exist; diff --git a/test/functional/index.test.js b/test/functional/index.test.js index 25f0d06140..c7aadacc7d 100644 --- a/test/functional/index.test.js +++ b/test/functional/index.test.js @@ -1034,48 +1034,6 @@ describe('Indexes', function() { } }); - /** - * @ignore - */ - it('should correctly error out due to driver close', { - metadata: { - requires: { topology: ['single'] }, - sessions: { skipLeakTests: true } - }, - - // The actual test we wish to run - test: function(done) { - var configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // The new topology type has loose concepts of 'closing' and 'opening' a client. It will - // simply attempt here to retry the connection and reconnect, so this is a bad test for - // the driver in that configuration. - - return this.skip(); - } - - var client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 }); - client.connect(function(err, client) { - var db = client.db(configuration.db); - client.close(function() { - setTimeout(() => { - db.createCollection('nonexisting', { w: 1 }, function(err) { - test.ok(err != null); - db.collection('nonexisting', { strict: true }, function(err) { - test.ok(err != null); - db.collection('nonexisting', { strict: false }, function(err) { - // When set to false (default) it should not create an error - test.ok(err === null); - setTimeout(() => done()); - }); - }); - }); - }); - }); - }); - } - }); - /** * @ignore */ diff --git a/test/functional/mongo_client.test.js b/test/functional/mongo_client.test.js index c46c81aea9..c8fc32e798 100644 --- a/test/functional/mongo_client.test.js +++ b/test/functional/mongo_client.test.js @@ -11,99 +11,6 @@ describe('MongoClient', function() { return setupDatabase(this.configuration); }); - it('Should Correctly Do MongoClient with bufferMaxEntries:0 and ordered execution', { - metadata: { - requires: { - topology: ['single', 'ssl', 'wiredtiger'] - } - }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // the new topology is far more resilient in these scenarios, making very difficult - // to reproduce the issues tested here. - return this.skip(); - } - - const client = configuration.newClient({}, { bufferMaxEntries: 0, sslValidate: false }); - - client.connect(function(err, client) { - var db = client.db(configuration.db); - // Listener for closing event - var closeListener = function() { - // Let's insert a document - var collection = db.collection('test_object_id_generation.data2'); - // Insert another test document and collect using ObjectId - var docs = []; - for (var i = 0; i < 1500; i++) docs.push({ a: i }); - - collection.insert(docs, configuration.writeConcern(), function(err) { - test.ok(err != null); - test.ok(err.message.indexOf('0') !== -1); - - // Let's close the db - client.close(done); - }); - }; - - // Add listener to close event - db.once('close', closeListener); - // Ensure death of server instance - client.topology.connections()[0].destroy(); - }); - } - }); - - it('Should Correctly Do MongoClient with bufferMaxEntries:0 and unordered execution', { - metadata: { - requires: { - topology: ['single', 'ssl', 'wiredtiger'] - } - }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // the new topology is far more resilient in these scenarios, making very difficult - // to reproduce the issues tested here. - return this.skip(); - } - - const client = configuration.newClient({}, { bufferMaxEntries: 0, sslValidate: false }); - - client.connect(function(err, client) { - var db = client.db(configuration.db); - // Listener for closing event - var closeListener = function() { - // Let's insert a document - var collection = db.collection('test_object_id_generation.data_3'); - // Insert another test document and collect using ObjectId - var docs = []; - for (var i = 0; i < 1500; i++) docs.push({ a: i }); - - var opts = configuration.writeConcern(); - opts.keepGoing = true; - // Execute insert - collection.insert(docs, opts, function(err) { - test.ok(err != null); - test.ok(err.message.indexOf('0') !== -1); - - // Let's close the db - client.close(done); - }); - }; - - // Add listener to close event - db.once('close', closeListener); - // Ensure death of server instance - client.topology.connections()[0].destroy(); - }); - } - }); - it('Should correctly pass through extra db options', { metadata: { requires: { @@ -159,267 +66,6 @@ describe('MongoClient', function() { } }); - it('Should correctly pass through extra server options', { - metadata: { - requires: { - topology: ['single'] - } - }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // skipped for direct legacy variable inspection - return this.skip(); - } - - const client = configuration.newClient( - {}, - { - poolSize: 10, - autoReconnect: false, - noDelay: false, - keepAlive: true, - keepAliveInitialDelay: 100, - connectTimeoutMS: 444444, - socketTimeoutMS: 555555 - } - ); - - client.connect(function(err, client) { - var db = client.db(configuration.db); - test.equal(10, db.s.topology.s.poolSize); - test.equal(false, db.s.topology.autoReconnect); - test.equal(444444, db.s.topology.s.clonedOptions.connectionTimeout); - test.equal(555555, db.s.topology.s.clonedOptions.socketTimeout); - test.equal(true, db.s.topology.s.clonedOptions.keepAlive); - test.equal(100, db.s.topology.s.clonedOptions.keepAliveInitialDelay); - - client.close(done); - }); - } - }); - - it.skip('Should correctly pass through extra replicaset options', { - metadata: { - requires: { - topology: ['replicaset'] - } - }, - - // The actual test we wish to run - test: function(done) { - // NOTE: skipped because this test is using explicit variable names not used by - // mongo-orchestration. This behavior should be unit tested without depending - // on the test harness used. - - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // skipped for direct legacy variable inspection - return this.skip(); - } - - var url = configuration.url().replace('rs_name=rs', 'rs_name=rs1'); - const client = configuration.newClient(url, { - replSet: { - ha: false, - haInterval: 10000, - replicaSet: 'rs', - secondaryAcceptableLatencyMS: 100, - connectWithNoPrimary: true, - poolSize: 1, - socketOptions: { - noDelay: false, - keepAlive: true, - keepAliveInitialDelay: 100, - connectTimeoutMS: 444444, - socketTimeoutMS: 555555 - } - } - }); - - client.connect(function(err, client) { - expect(err).to.not.exist; - var db = client.db(configuration.db); - - test.equal(false, db.s.topology.s.clonedOptions.ha); - test.equal(10000, db.s.topology.s.clonedOptions.haInterval); - test.equal('rs', db.s.topology.s.clonedOptions.setName); - test.equal(100, db.s.topology.s.clonedOptions.acceptableLatency); - test.equal(true, db.s.topology.s.clonedOptions.secondaryOnlyConnectionAllowed); - test.equal(1, db.s.topology.s.clonedOptions.size); - - test.equal(444444, db.s.topology.s.clonedOptions.connectionTimeout); - test.equal(555555, db.s.topology.s.clonedOptions.socketTimeout); - test.equal(true, db.s.topology.s.clonedOptions.keepAlive); - test.equal(100, db.s.topology.s.clonedOptions.keepAliveInitialDelay); - - client.close(done); - }); - } - }); - - it('Should correctly pass through extra sharded options', { - metadata: { - requires: { - topology: ['sharded'] - } - }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // skipped for direct legacy variable inspection - return this.skip(); - } - - const client = configuration.newClient( - {}, - { - ha: false, - haInterval: 10000, - acceptableLatencyMS: 100, - poolSize: 1, - socketOptions: { - noDelay: false, - keepAlive: true, - keepAliveInitialDelay: 100, - connectTimeoutMS: 444444, - socketTimeoutMS: 555555 - } - } - ); - - client.connect(function(err, client) { - expect(err).to.not.exist; - var db = client.db(configuration.db); - - test.equal(false, db.s.topology.s.clonedOptions.ha); - test.equal(10000, db.s.topology.s.clonedOptions.haInterval); - test.equal(100, db.s.topology.s.clonedOptions.localThresholdMS); - test.equal(1, db.s.topology.s.clonedOptions.poolSize); - - test.equal(444444, db.s.topology.s.clonedOptions.connectionTimeout); - test.equal(555555, db.s.topology.s.clonedOptions.socketTimeout); - test.equal(true, db.s.topology.s.clonedOptions.keepAlive); - test.equal(100, db.s.topology.s.clonedOptions.keepAliveInitialDelay); - - client.close(done); - }); - } - }); - - it('Should correctly set MaxPoolSize on single server', { - metadata: { - requires: { - topology: ['single'] - } - }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // skipped for direct legacy variable inspection - return this.skip(); - } - - var url = configuration.url(); - url = - url.indexOf('?') !== -1 - ? f('%s&%s', url, 'maxPoolSize=100') - : f('%s?%s', url, 'maxPoolSize=100'); - - const client = configuration.newClient(url); - client.connect(function(err, client) { - test.equal(1, client.topology.connections().length); - test.equal(100, client.topology.s.coreTopology.s.pool.size); - - client.close(done); - }); - } - }); - - it('Should correctly set MaxPoolSize on replicaset server', { - metadata: { - requires: { - topology: ['replicaset'], - unifiedTopology: false - } - }, - - // The actual test we wish to run - test: function(done) { - var configuration = this.configuration; - var url = configuration.url(); - url = - url.indexOf('?') !== -1 - ? f('%s&%s', url, 'maxPoolSize=100') - : f('%s?%s', url, 'maxPoolSize=100'); - - const client = configuration.newClient(url); - client.connect(function(err, client) { - test.ok(client.topology.connections().length >= 1); - - var connections = client.topology.connections(); - - for (var i = 0; i < connections.length; i++) { - test.equal(10000, connections[i].connectionTimeout); - test.equal(360000, connections[i].socketTimeout); - } - - client.close(); - - const secondClient = configuration.newClient(url, { - connectTimeoutMS: 15000, - socketTimeoutMS: 30000 - }); - - secondClient.connect(function(err) { - test.equal(null, err); - test.ok(secondClient.topology.connections().length >= 1); - - var connections = secondClient.topology.connections(); - - for (var i = 0; i < connections.length; i++) { - test.equal(15000, connections[i].connectionTimeout); - test.equal(30000, connections[i].socketTimeout); - } - - secondClient.close(done); - }); - }); - } - }); - - it('Should correctly set MaxPoolSize on sharded server', { - metadata: { - requires: { - topology: ['sharded'], - unifiedTopology: false - } - }, - - // The actual test we wish to run - test: function(done) { - var configuration = this.configuration; - var url = configuration.url(); - url = - url.indexOf('?') !== -1 - ? f('%s&%s', url, 'maxPoolSize=100') - : f('%s?%s', url, 'maxPoolSize=100'); - - const client = configuration.newClient(url); - client.connect(function(err, client) { - test.ok(client.topology.connections().length >= 1); - - client.close(done); - }); - } - }); - /** * @ignore */ @@ -499,76 +145,6 @@ describe('MongoClient', function() { } }); - /** - * @ignore - */ - it('correctly connect setting keepAlive to 100', { - metadata: { - requires: { - topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'], - unifiedTopology: false - } - }, - - // The actual test we wish to run - test: function(done) { - var configuration = this.configuration; - const client = configuration.newClient( - {}, - { - keepAlive: true, - keepAliveInitialDelay: 100 - } - ); - - client.connect(function(err, client) { - test.equal(null, err); - var connection = client.topology.connections()[0]; - test.equal(true, connection.keepAlive); - test.equal(100, connection.keepAliveInitialDelay); - - client.close(); - - const secondClient = configuration.newClient({}, { keepAlive: false }); - secondClient.connect(function(err) { - test.equal(null, err); - - secondClient.topology.connections().forEach(function(x) { - test.equal(false, x.keepAlive); - }); - - secondClient.close(done); - }); - }); - } - }); - - /** - * @ignore - */ - it('default keepAlive behavior', { - metadata: { - requires: { - topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'], - unifiedTopology: false - } - }, - - // The actual test we wish to run - test: function(done) { - var configuration = this.configuration; - const client = configuration.newClient(); - client.connect(function(err, client) { - test.equal(null, err); - client.topology.connections().forEach(function(x) { - test.equal(true, x.keepAlive); - }); - - client.close(done); - }); - } - }); - it('should fail dure to garbage connection string', { metadata: { requires: { @@ -590,38 +166,6 @@ describe('MongoClient', function() { } }); - it.skip('Should fail to connect due to instances not being mongos proxies', { - metadata: { - requires: { - topology: ['replicaset'] - } - }, - - // The actual test we wish to run - test: function(done) { - // NOTE: skipped because this test is using explicit variable names not used by - // mongo-orchestration. This behavior should be unit tested without depending - // on the test harness used. - - var configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // this is no longer relevant with the unified topology - return this.skip(); - } - - var url = configuration - .url() - .replace('replicaSet=rs', '') - .replace('localhost:31000', 'localhost:31000,localhost:31001'); - - const client = configuration.newClient(url); - client.connect(function(err) { - test.ok(err != null); - done(); - }); - } - }); - it('Should correctly pass through appname', { metadata: { requires: { @@ -706,33 +250,6 @@ describe('MongoClient', function() { } }); - it('Should correctly pass through socketTimeoutMS and connectTimeoutMS from uri', { - metadata: { - requires: { - topology: ['single'] - } - }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // skipped for direct legacy variable inspection - return this.skip(); - } - - var uri = f('%s?socketTimeoutMS=120000&connectTimeoutMS=15000', configuration.url()); - const client = configuration.newClient(uri); - client.connect(function(err, client) { - test.equal(null, err); - test.equal(120000, client.topology.s.coreTopology.s.options.socketTimeout); - test.equal(15000, client.topology.s.coreTopology.s.options.connectionTimeout); - - client.close(done); - }); - } - }); - ////////////////////////////////////////////////////////////////////////////////////////// // // new MongoClient connection tests @@ -790,28 +307,6 @@ describe('MongoClient', function() { } }); - it('Should use compression from URI', { - metadata: { requires: { topology: ['single'], unifiedTopology: false } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - const url = `mongodb://${configuration.host}:${configuration.port}/?compressors=zlib`; - const client = configuration.newClient(url, { useNewUrlParser: true }); - - client.connect(function(err, client) { - expect(err).to.not.exist; - - const db = client.db('integration_tests'); - db.collection('new_mongo_client_collection').insertOne({ a: 1 }, (err, r) => { - expect(err).to.not.exist; - expect(r.connection.options.compression).to.deep.equal({ compressors: ['zlib'] }); - client.close(done); - }); - }); - } - }); - it('should be able to access a database named "constructor"', function() { const client = this.configuration.newClient(); let err; diff --git a/test/functional/mongo_client_options.test.js b/test/functional/mongo_client_options.test.js index efdf2c6c40..eff199c602 100644 --- a/test/functional/mongo_client_options.test.js +++ b/test/functional/mongo_client_options.test.js @@ -8,66 +8,6 @@ describe('MongoClient Options', function() { return setupDatabase(this.configuration); }); - /** - * @ignore - */ - it('pass in server and db top level options', { - metadata: { requires: { topology: 'single' } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // skipped for direct legacy variable inspection - return this.skip(); - } - - const client = configuration.newClient(configuration.url(), { - autoReconnect: true, - poolSize: 4 - }); - - client.connect( - connectionTester(configuration, 'testConnectServerOptions', function(client) { - test.ok(client.topology.poolSize >= 1); - test.equal(4, client.topology.s.coreTopology.s.pool.size); - test.equal(true, client.topology.autoReconnect); - client.close(done); - }) - ); - } - }); - - /** - * @ignore - */ - it('pass in server and db top level options', { - metadata: { requires: { topology: 'single' } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // skipped for direct legacy variable inspection - return this.skip(); - } - - const client = configuration.newClient(configuration.url(), { - autoReconnect: true, - poolSize: 4 - }); - - client.connect( - connectionTester(configuration, 'testConnectServerOptions', function(client) { - test.ok(client.topology.poolSize >= 1); - test.equal(4, client.topology.s.coreTopology.s.pool.size); - test.equal(true, client.topology.autoReconnect); - client.close(done); - }) - ); - } - }); - /** * @ignore */ diff --git a/test/functional/operation_example.test.js b/test/functional/operation_example.test.js index 45b89d3b5b..6fa883dc52 100644 --- a/test/functional/operation_example.test.js +++ b/test/functional/operation_example.test.js @@ -3599,68 +3599,6 @@ describe('Operation Examples', function() { } }); - /** - * An example that shows how to force close a db connection so it cannot be reused. - * - * @example-class Db - * @example-method close - * @ignore - */ - it('shouldCorrectlyFailOnRetryDueToAppCloseOfDb', { - metadata: { - requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } - }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // The new topology type has loose concepts of 'closing' and 'opening' a client. It will - // simply attempt here to retry the connection and reconnect, so this is a bad test for - // the driver in that configuration. - - return this.skip(); - } - - var client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 }); - client.connect(function(err, client) { - // LINE var MongoClient = require('mongodb').MongoClient, - // LINE test = require('assert'); - // LINE const client = new MongoClient('mongodb://localhost:27017/test'); - // LINE client.connect(function(err, client) { - // LINE var db = client.db('test); - // REPLACE configuration.writeConcernMax() WITH {w:1} - // REMOVE-LINE restartAndDone - // REMOVE-LINE done(); - // REMOVE-LINE var db = client.db(configuration.db); - // BEGIN - var db = client.db(configuration.db); - // Fetch a collection - var collection = db.collection('shouldCorrectlyFailOnRetryDueToAppCloseOfDb'); - - // Insert a document - collection.insertOne({ a: 1 }, configuration.writeConcernMax(), function(err, result) { - test.ok(result); - test.equal(null, err); - - // Force close the connection - client.close(true, function(err) { - test.equal(null, err); - - // Attemp to insert should fail now with correct message 'db closed by application' - collection.insertOne({ a: 2 }, configuration.writeConcernMax(), function(err, result) { - expect(err).to.exist; - expect(result).to.not.exist; - - client.close(done); - }); - }); - }); - }); - // END - } - }); - /** * An example of a simple single server db connection * diff --git a/test/functional/operation_generators_example.test.js b/test/functional/operation_generators_example.test.js index 2b4fbf8aae..fd36dc26dc 100644 --- a/test/functional/operation_generators_example.test.js +++ b/test/functional/operation_generators_example.test.js @@ -2791,68 +2791,6 @@ describe('Operation (Generators)', function() { * *************************************************************************/ - /** - * An example that shows how to force close a db connection so it cannot be reused using a Generator and the co module.. - * - * @example-class Db - * @example-method close - * @ignore - */ - it('shouldCorrectlyFailOnRetryDueToAppCloseOfDbWithGenerators', { - metadata: { requires: { generators: true, topology: ['single'] } }, - - // The actual test we wish to run - test: function() { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // The new topology type has loose concepts of 'closing' and 'opening' a client. It will - // simply attempt here to retry the connection and reconnect, so this is a bad test for - // the driver in that configuration. - - return this.skip(); - } - - var co = require('co'); - return co(function*() { - // Connect - var client = yield configuration - .newClient(configuration.writeConcernMax(), { poolSize: 1 }) - .connect(); - var db = client.db(configuration.db); - // LINE var MongoClient = require('mongodb').MongoClient, - // LINE co = require('co'); - // LINE test = require('assert'); - // LINE - // LINE co(function*() { - // LINE const client = new MongoClient('mongodb://localhost:27017/test'); - // LINE yield client.connect(); - // LINE - // LINE var db = client.db('test'); - // REPLACE configuration.writeConcernMax() WITH {w:1} - // BEGIN - - // Fetch a collection - var collection = db.collection( - 'shouldCorrectlyFailOnRetryDueToAppCloseOfDb_with_generators' - ); - - // Insert a document - yield collection.insertOne({ a: 1 }, configuration.writeConcernMax()); - - // Force close the connection - yield client.close(true); - - try { - // Attemp to insert should fail now with correct message 'db closed by application' - yield collection.insertOne({ a: 2 }, configuration.writeConcernMax()); - } catch (err) { - yield client.close(); - } - }); - // END - } - }); - /** * An example of retrieving the collections list for a database using a Generator and the co module. * diff --git a/test/functional/operation_promises_example.test.js b/test/functional/operation_promises_example.test.js index 803da770cb..102ab5e8aa 100644 --- a/test/functional/operation_promises_example.test.js +++ b/test/functional/operation_promises_example.test.js @@ -2871,67 +2871,6 @@ describe('Operation (Promises)', function() { * *************************************************************************/ - /** - * An example that shows how to force close a db connection so it cannot be reused using a Promise.. - * - * @example-class Db - * @example-method close - * @ignore - */ - it('shouldCorrectlyFailOnRetryDueToAppCloseOfDbWithPromises', { - metadata: { requires: { topology: ['single'] } }, - - // The actual test we wish to run - test: function() { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // The new topology type has loose concepts of 'closing' and 'opening' a client. It will - // simply attempt here to retry the connection and reconnect, so this is a bad test for - // the driver in that configuration. - - return this.skip(); - } - - var client = configuration.newClient(configuration.writeConcernMax(), { - poolSize: 1, - auto_reconnect: false - }); - - return client.connect().then(function(client) { - var db = client.db(configuration.db); - // LINE var MongoClient = require('mongodb').MongoClient, - // LINE test = require('assert'); - // LINE const client = new MongoClient('mongodb://localhost:27017/test'); - // LINE client.connect().then(() => { - // LINE var db = client.db('test); - // REPLACE configuration.writeConcernMax() WITH {w:1} - // REMOVE-LINE done(); - // BEGIN - - // Fetch a collection - var collection = db.collection('shouldCorrectlyFailOnRetryDueToAppCloseOfDb_with_promise'); - - // Insert a document - return collection - .insertOne({ a: 1 }, configuration.writeConcernMax()) - .then(function(result) { - test.ok(result); - // Force close the connection - return client.close(true); - }) - .then(function() { - // Attemp to insert should fail now with correct message 'db closed by application' - return collection.insertOne({ a: 2 }, configuration.writeConcernMax()); - }) - .catch(function(err) { - test.ok(err); - return client.close(); - }); - }); - // END - } - }); - /** * An example of a simple single server db connection and close function using a Promise. * diff --git a/test/functional/replicaset_mock.test.js b/test/functional/replicaset_mock.test.js index ca063a55cb..dcf0e107fc 100644 --- a/test/functional/replicaset_mock.test.js +++ b/test/functional/replicaset_mock.test.js @@ -139,33 +139,4 @@ describe('ReplSet (mocks)', function() { }); } }); - - it('Should correctly set socketTimeoutMS and connectTimeoutMS for mongos', { - metadata: { - requires: { - generators: true, - topology: 'single' - } - }, - - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // skipped for direct legacy variable inspection - return this.skip(); - } - - const client = configuration.newClient( - `mongodb://${test.mongos1.uri()},${test.mongos2.uri()}/test?socketTimeoutMS=120000&connectTimeoutMS=15000` - ); - - client.connect(function(err, client) { - expect(err).to.not.exist; - expect(client.topology.s.coreTopology.s.options.connectionTimeout).to.equal(15000); - expect(client.topology.s.coreTopology.s.options.socketTimeout).to.equal(120000); - - client.close(done); - }); - } - }); }); diff --git a/test/functional/sharding_connection.test.js b/test/functional/sharding_connection.test.js deleted file mode 100644 index fc4acfe7c3..0000000000 --- a/test/functional/sharding_connection.test.js +++ /dev/null @@ -1,162 +0,0 @@ -'use strict'; - -const setupDatabase = require('./shared').setupDatabase; -const expect = require('chai').expect; - -describe('Sharding (Connection)', function() { - before(function() { - return setupDatabase(this.configuration); - }); - - /** - * @ignore - */ - it('Should connect to mongos proxies using connectiong string and options', { - metadata: { requires: { topology: 'sharded' } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // disable for inspection of legacy properties - return this.skip(); - } - - const url = `${configuration.url()}?w=1&readPreference=secondaryPreferred&readPreferenceTags=sf%3A1`; - const client = configuration.newClient(url, { haInterval: 500, useNewUrlParser: true }); - - client.connect(err => { - expect(err).to.not.exist; - expect(client).to.have.nested.property('topology.haInterval', 500); - - const db = client.db(configuration.db); - - db.collection('replicaset_mongo_client_collection').update( - { a: 1 }, - { b: 1 }, - { upsert: true }, - (err, result) => { - expect(err).to.not.exist; - expect(result).to.have.nested.property('result.n', 1); - - // Perform fetch of document - db.collection('replicaset_mongo_client_collection').findOne(err => { - expect(err).to.not.exist; - - client.close(done); - }); - } - ); - }); - } - }); - - /** - * @ignore - */ - it('Should correctly connect with a missing mongos', { - metadata: { requires: { topology: 'sharded' } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // the unified topology will attempt to connect to all provided servers if you - // want to explicitly call `connect`. Otherwise, it will satisfy the requirements - // of this test, and not explicitly fail on an unknown server. - return this.skip(); - } - - const host = configuration.host; - const port = configuration.port; - - // TODO: Better way to do this? - const url = `mongodb://${host}:${port},${host}:${port + - 1},localhost:50002/sharded_test_db?w=1`; - - const client = configuration.newClient(url, { useNewUrlParser: true }); - - client.connect(err => { - expect(err).to.not.exist; - client.close(done); - }); - } - }); - - /** - * @ignore - */ - it('Should exercise all options on mongos topology', { - metadata: { requires: { topology: 'sharded' } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // disable for inspection of legacy properties - return this.skip(); - } - - const url = `${configuration.url()}?w=1&readPreference=secondaryPreferred&readPreferenceTags=sf%3A1`; - - const client = configuration.newClient(url, { useNewUrlParser: true, haInterval: 500 }); - client.connect(function(err) { - expect(err).to.not.exist; - expect(client) - .to.have.property('topology') - .that.is.an('object'); - - const topology = client.topology; - - expect(topology).to.have.property('haInterval', 500); - expect(topology).to.have.property('bson').that.does.exist; - - expect(topology) - .to.have.property('isConnected') - .that.is.a('function'); - expect(topology.isConnected()).to.equal(true); - - ['capabilities', 'lastIsMaster', 'connections'].forEach(member => { - expect(topology) - .to.have.property(member) - .that.is.a('function'); - expect(topology[member]()).to.exist; - }); - - client.close(done); - }); - } - }); - - /** - * @ignore - */ - it('Should correctly modify the server reconnectTries for all sharded proxy instances', { - metadata: { requires: { topology: 'sharded' } }, - - // The actual test we wish to run - test: function(done) { - const configuration = this.configuration; - if (configuration.usingUnifiedTopology()) { - // disable for inspection of legacy properties - return this.skip(); - } - - const url = `${configuration.url()}?w=1&readPreference=secondaryPreferred&readPreferenceTags=sf%3A1`; - - const client = configuration.newClient(url, { useNewUrlParser: true, reconnectTries: 10 }); - client.connect(function(err) { - expect(err).to.not.exist; - expect(client) - .to.have.nested.property('topology.s.coreTopology.connectedProxies') - .that.is.an('array'); - - client.topology.s.coreTopology.connectedProxies.forEach(server => { - expect(server).to.have.nested.property('s.pool.options.reconnectTries', 10); - }); - - client.close(done); - }); - } - }); -}); diff --git a/test/functional/spec-runner/context.js b/test/functional/spec-runner/context.js index 04a8faac0d..b711124796 100644 --- a/test/functional/spec-runner/context.js +++ b/test/functional/spec-runner/context.js @@ -24,13 +24,12 @@ class TestRunnerContext { setup(config) { this.sharedClient = config.newClient( - resolveConnectionString(config, { useMultipleMongoses: true }), - { useUnifiedTopology: true } + resolveConnectionString(config, { useMultipleMongoses: true }) ); if (config.topologyType === 'Sharded') { this.failPointClients = config.options.hosts.map(proxy => - config.newClient(`mongodb://${proxy.host}:${proxy.port}/`, { useUnifiedTopology: true }) + config.newClient(`mongodb://${proxy.host}:${proxy.port}/`) ); } diff --git a/test/functional/spec-runner/index.js b/test/functional/spec-runner/index.js index bcd4e19243..5dd159f4e8 100644 --- a/test/functional/spec-runner/index.js +++ b/test/functional/spec-runner/index.js @@ -235,9 +235,6 @@ function runTestSuiteTest(configuration, spec, context) { clientOptions.haInterval = 100; clientOptions.useRecoveryToken = true; - // TODO: this should be configured by `newClient` and env variables - clientOptions.useUnifiedTopology = true; - const url = resolveConnectionString(configuration, spec); const client = configuration.newClient(url, clientOptions); return client.connect().then(client => { diff --git a/test/functional/transactions.test.js b/test/functional/transactions.test.js index 0ded0c703e..d661660338 100644 --- a/test/functional/transactions.test.js +++ b/test/functional/transactions.test.js @@ -103,7 +103,7 @@ describe('Transactions', function() { metadata: { requires: { topology: ['sharded'], mongodb: '>=4.1.0' } }, test: function(done) { const configuration = this.configuration; - const client = configuration.newClient(configuration.url(), { useUnifiedTopology: true }); + const client = configuration.newClient(configuration.url()); client.connect(err => { expect(err).to.not.exist; @@ -127,7 +127,7 @@ describe('Transactions', function() { metadata: { requires: { topology: 'replicaset', mongodb: '>=4.0.0' } }, test: function(done) { const configuration = this.configuration; - const client = configuration.newClient({ w: 1 }, { useUnifiedTopology: true }); + const client = configuration.newClient({ w: 1 }); client.connect(err => { expect(err).to.not.exist; @@ -170,7 +170,7 @@ describe('Transactions', function() { metadata: { requires: { topology: 'replicaset', mongodb: '>=4.0.0' } }, test: function(done) { const configuration = this.configuration; - const client = configuration.newClient({ w: 1 }, { useUnifiedTopology: true }); + const client = configuration.newClient({ w: 1 }); client.connect(err => { expect(err).to.not.exist; diff --git a/test/functional/uri.test.js b/test/functional/uri.test.js index a98b77e037..b6c8f2baf7 100644 --- a/test/functional/uri.test.js +++ b/test/functional/uri.test.js @@ -6,47 +6,6 @@ const ReplSet = require('../../lib/topologies/replset'); const NativeTopology = require('../../lib/topologies/native_topology'); describe('URI', function() { - /** - * @ignore - */ - it( - 'Should correctly connect using MongoClient to a single server using connect with optional server setting', - { - // Add a tag that our runner can trigger on - // in this case we are setting that node needs to be higher than 0.10.X to run - metadata: { requires: { topology: 'single', unifiedTopology: false } }, - - // The actual test we wish to run - test: function(done) { - var self = this; - - // Connect using the connection string - const client = this.configuration.newClient('mongodb://localhost:27017/integration_tests', { - native_parser: false, - socketOptions: { - connectTimeoutMS: 500 - } - }); - - client.connect(function(err, client) { - var db = client.db(self.configuration.db); - expect(err).to.not.exist; - expect(client.topology.connections()[0].connectionTimeout).to.equal(500); - - db.collection('mongoclient_test').update({ a: 1 }, { b: 1 }, { upsert: true }, function( - err, - result - ) { - expect(err).to.not.exist; - expect(result.result.n).to.equal(1); - - client.close(done); - }); - }); - } - } - ); - /** * @ignore */ diff --git a/test/tools/atlas_connectivity_tests.js b/test/tools/atlas_connectivity_tests.js index e6947bbdbc..156346145c 100644 --- a/test/tools/atlas_connectivity_tests.js +++ b/test/tools/atlas_connectivity_tests.js @@ -12,11 +12,7 @@ const CONFIGS = ['ATLAS_REPL', 'ATLAS_SHRD', 'ATLAS_FREE', 'ATLAS_TLS11', 'ATLAS ); function runConnectionTest(config) { - const client = new MongoClient(config.url, { - useNewUrlParser: true, - // TODO: We should test both the unified and not-unified cases - useUnifiedTopology: false - }); + const client = new MongoClient(config.url); return Promise.resolve() .then(() => console.log(`testing ${config.name}`)) .then(() => client.connect()) diff --git a/test/tools/runner/config.js b/test/tools/runner/config.js index 1b81398992..6ce05145f0 100644 --- a/test/tools/runner/config.js +++ b/test/tools/runner/config.js @@ -63,7 +63,7 @@ class NativeConfiguration { } usingUnifiedTopology() { - return !!process.env.MONGODB_UNIFIED_TOPOLOGY; + return true; } newClient(dbOptions, serverOptions) { @@ -72,17 +72,17 @@ class NativeConfiguration { return new MongoClient( dbOptions, this.usingUnifiedTopology() - ? Object.assign({ useUnifiedTopology: true, minHeartbeatFrequencyMS: 100 }, serverOptions) + ? Object.assign({ minHeartbeatFrequencyMS: 100 }, serverOptions) : serverOptions ); } dbOptions = dbOptions || {}; - serverOptions = Object.assign({}, { haInterval: 100 }, serverOptions); - if (this.usingUnifiedTopology()) { - serverOptions.useUnifiedTopology = true; - serverOptions.minHeartbeatFrequencyMS = 100; - } + serverOptions = Object.assign( + {}, + { haInterval: 100, minHeartbeatFrequencyMS: 100 }, + serverOptions + ); // Fall back let dbHost = (serverOptions && serverOptions.host) || this.options.host; diff --git a/test/tools/runner/index.js b/test/tools/runner/index.js index d18a70ade4..15fcac4a06 100644 --- a/test/tools/runner/index.js +++ b/test/tools/runner/index.js @@ -60,7 +60,7 @@ before(function(_done) { // )} topology` // ); - const client = new MongoClient(MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true }); + const client = new MongoClient(MONGODB_URI); const done = err => client.close(err2 => _done(err || err2)); client.connect(err => { diff --git a/test/tools/sdam_viz b/test/tools/sdam_viz index 31b69e8145..2426ee1300 100755 --- a/test/tools/sdam_viz +++ b/test/tools/sdam_viz @@ -9,8 +9,6 @@ const argv = require('yargs') .demandCommand(1) .help('h') .describe('workload', 'Simulate a read workload') - .describe('legacy', 'Use the legacy topology types') - .alias('l', 'legacy') .alias('w', 'workload') .alias('h', 'help').argv; @@ -19,17 +17,10 @@ function print(msg) { } const uri = argv._[0]; -const client = new MongoClient(uri, { - useNewUrlParser: true, - useUnifiedTopology: !argv.legacy -}); +const client = new MongoClient(uri); async function run() { - print( - `connecting to: ${chalk.bold(uri)} using ${chalk.bold( - argv.legacy ? 'legacy' : 'unified' - )} topology` - ); + print(`connecting to: ${chalk.bold(uri)}`); visualizeMonitoringEvents(client); await client.connect(); diff --git a/test/unit/change_stream_resume.test.js b/test/unit/change_stream_resume.test.js index 61efd11a3f..6b86cd98b2 100644 --- a/test/unit/change_stream_resume.test.js +++ b/test/unit/change_stream_resume.test.js @@ -183,10 +183,7 @@ describe('Change Stream Resume Tests', function() { metadata: { requires: { topology: 'single' } }, test: function() { const configuration = this.configuration; - if (!configuration.usingUnifiedTopology()) { - // These tests take way too long with the non-unified topology, so we will skip them - return this.skip(); - } + test.server.setMessageHandler(makeServerHandler(config)); client = configuration.newClient(`mongodb://${test.server.uri()}`, { socketTimeoutMS: 300 diff --git a/test/unit/client.test.js b/test/unit/client.test.js index 5901c3c98c..f86c074b41 100644 --- a/test/unit/client.test.js +++ b/test/unit/client.test.js @@ -24,7 +24,6 @@ describe('Client (unit)', function() { }); const client = this.configuration.newClient(`mongodb://${server.uri()}/`, { - useUnifiedTopology: true, driverInfo: { name: 'mongoose', version: '5.7.10',