From 16f9a1ccd339795576be786064a71c66dc591f10 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Fri, 10 May 2019 18:11:56 -0400 Subject: [PATCH] refactor: minor modifications required to use core with native --- .eslintrc | 3 +- index.js | 8 +- lib/aggregation_cursor.js | 2 +- lib/bulk/common.js | 10 +- lib/change_stream.js | 2 +- lib/collection.js | 6 +- lib/command_cursor.js | 4 +- lib/core/cursor.js | 27 ----- lib/core/index.js | 50 +++++++++ lib/core/topologies/mongos.js | 14 --- lib/core/topologies/read_preference.js | 23 +--- lib/core/topologies/shared.js | 2 +- lib/cursor.js | 10 +- lib/db.js | 8 +- lib/error.js | 4 +- lib/gridfs-stream/upload.js | 2 +- lib/gridfs/chunk.js | 4 +- lib/gridfs/grid_store.js | 8 +- lib/mongo_client.js | 2 +- lib/operations/add_user.js | 4 +- lib/operations/aggregate.js | 2 +- lib/operations/aggregate_operation.js | 2 +- lib/operations/bulk_write.js | 2 +- lib/operations/collection_ops.js | 8 +- lib/operations/command.js | 2 +- lib/operations/common_functions.js | 4 +- lib/operations/connect.js | 12 +-- lib/operations/create_collection.js | 4 +- lib/operations/create_index.js | 4 +- lib/operations/create_indexes.js | 4 +- lib/operations/cursor_ops.js | 2 +- lib/operations/db_ops.js | 6 +- lib/operations/drop_collection.js | 2 +- lib/operations/drop_database.js | 2 +- lib/operations/execute_db_admin_command.js | 2 +- lib/operations/execute_operation_v2.js | 2 +- lib/operations/explain.js | 2 +- lib/operations/find_and_modify.js | 2 +- lib/operations/insert_many.js | 2 +- lib/operations/insert_one.js | 2 +- lib/operations/list_indexes.js | 2 +- lib/operations/map_reduce.js | 2 +- lib/operations/mongo_client_ops.js | 12 +-- lib/operations/options_operation.js | 2 +- lib/operations/remove_user.js | 4 +- lib/topologies/mongos.js | 6 +- lib/topologies/native_topology.js | 4 +- lib/topologies/replset.js | 6 +- lib/topologies/server.js | 8 +- lib/topologies/topology_base.js | 4 +- lib/url_parser.js | 4 +- lib/utils.js | 4 +- package-lock.json | 19 ++-- package.json | 16 ++- test/config.js | 50 ++++++++- .../basic_replset_server_auth_tests.js | 6 +- .../basic_single_server_auth_tests.js | 72 +++++++------ test/core/functional/client_metadata_tests.js | 29 ++--- test/core/functional/connection_tests.js | 2 +- test/core/functional/cursor_tests.js | 2 +- test/core/functional/error_tests.js | 8 +- test/core/functional/extend_cursor_tests.js | 16 ++- test/core/functional/max_staleness_tests.js | 8 +- .../mongos_mocks/mixed_seed_list_tests.js | 30 +++--- .../mongos_mocks/multiple_proxies_tests.js | 13 ++- .../mongos_mocks/proxy_failover_tests.js | 15 ++- .../proxy_read_preference_tests.js | 22 ++-- .../single_proxy_connection_tests.js | 19 ++-- .../mongos_server_selection_tests.js | 6 +- .../functional/operation_example_tests.js | 45 ++------ test/core/functional/operations_tests.js | 6 +- test/core/functional/pool_tests.js | 8 +- .../replset_server_selection_tests.js | 14 +-- test/core/functional/replset_state_tests.js | 2 +- test/core/functional/replset_tests.js | 16 +-- .../functional/rs_mocks/add_remove_tests.js | 26 ++--- .../rs_mocks/all_servers_close_tests.js | 20 ++-- .../functional/rs_mocks/connection_tests.js | 50 ++------- .../functional/rs_mocks/failover_tests.js | 23 ++-- .../rs_mocks/maintanance_mode_tests.js | 17 +-- .../functional/rs_mocks/monitoring_tests.js | 20 ++-- .../rs_mocks/no_primary_found_tests.js | 9 +- .../functional/rs_mocks/operation_tests.js | 14 ++- .../rs_mocks/primary_loses_network_tests.js | 9 +- .../rs_mocks/read_preferences_tests.js | 63 +++-------- .../mongos_topology_tests.js | 15 ++- .../replset_topology_tests.js | 13 +-- .../single_topology_tests.js | 24 ++--- test/core/functional/server_tests.js | 100 +++++------------- test/core/functional/shared.js | 10 +- .../single_mocks/compression_tests.js | 70 ++++++------ .../functional/single_mocks/timeout_tests.js | 36 +++---- test/core/functional/srv_polling_tests.js | 10 +- test/core/unit/apm_tests.js | 6 +- test/core/unit/common.js | 24 ++++- test/core/unit/connect_tests.js | 6 +- test/core/unit/connection_string_tests.js | 4 +- test/core/unit/mongodb_srv_tests.js | 2 +- test/core/unit/mongos/events_tests.js | 2 +- test/core/unit/mongos/reconnect_tests.js | 4 +- .../unit/mongos/retryable_writes_tests.js | 26 +++-- test/core/unit/mongos/sessions_tests.js | 19 ++-- test/core/unit/pool_tests.js | 6 +- test/core/unit/replset/auth_tests.js | 6 +- test/core/unit/replset/compression_tests.js | 2 +- .../unit/replset/read_preference_tests.js | 6 +- .../unit/replset/retryable_writes_tests.js | 18 ++-- test/core/unit/replset/sessions_tests.js | 2 +- test/core/unit/replset/step_down_tests.js | 2 +- .../transactions_feature_decoration_tests.js | 24 +++-- test/core/unit/response_test.js | 4 +- test/core/unit/scram_iterations_tests.js | 4 +- test/core/unit/sdam_spec_tests.js | 10 +- test/core/unit/server_selection_spec_tests.js | 16 +-- test/core/unit/sessions_tests.js | 42 ++++++-- test/core/unit/single/sessions_tests.js | 71 +++++++++---- test/core/unit/wire_protocol_test.js | 4 +- test/core/unit/write_concern_error_tests.js | 4 +- test/environments.js | 43 +++++--- test/functional/change_stream_tests.js | 2 +- test/functional/cursor_tests.js | 5 +- test/functional/raw_tests.js | 2 +- test/functional/replset_connection_tests.js | 2 +- test/functional/scram_sha_256_tests.js | 2 +- test/functional/session_leak_test.js | 2 +- test/functional/transactions_tests.js | 2 +- test/functional/uri_options_spec_tests.js | 6 +- test/functional/url_parser_tests.js | 5 +- test/tools/utils.js | 2 +- test/unit/change_stream_resume_tests.js | 2 +- test/unit/db_tests.js | 8 ++ 131 files changed, 819 insertions(+), 850 deletions(-) create mode 100644 lib/core/index.js diff --git a/.eslintrc b/.eslintrc index 5832bddc8a..2137437304 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,7 +4,8 @@ ], "env": { "node": true, - "mocha": true + "mocha": true, + "es6": true }, "globals": { "Promise": true, diff --git a/index.js b/index.js index fe305d6a2c..1817999c55 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ 'use strict'; // Core module -const core = require('mongodb-core'); +const core = require('./lib/core'); const Instrumentation = require('./lib/apm'); // Set up the connect function @@ -19,7 +19,7 @@ connect.Collection = require('./lib/collection'); connect.Server = require('./lib/topologies/server'); connect.ReplSet = require('./lib/topologies/replset'); connect.Mongos = require('./lib/topologies/mongos'); -connect.ReadPreference = require('mongodb-core').ReadPreference; +connect.ReadPreference = core.ReadPreference; connect.GridStore = require('./lib/gridfs/grid_store'); connect.Chunk = require('./lib/gridfs/chunk'); connect.Logger = core.Logger; @@ -28,8 +28,8 @@ connect.CommandCursor = require('./lib/command_cursor'); connect.Cursor = require('./lib/cursor'); connect.GridFSBucket = require('./lib/gridfs-stream'); // Exported to be used in tests not to be used anywhere else -connect.CoreServer = require('mongodb-core').Server; -connect.CoreConnection = require('mongodb-core').Connection; +connect.CoreServer = core.Server; +connect.CoreConnection = core.Connection; // BSON types exported connect.Binary = core.BSON.Binary; diff --git a/lib/aggregation_cursor.js b/lib/aggregation_cursor.js index 98a5b4433a..052bfbcc1a 100644 --- a/lib/aggregation_cursor.js +++ b/lib/aggregation_cursor.js @@ -1,7 +1,7 @@ 'use strict'; const inherits = require('util').inherits; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('./core').MongoError; const Readable = require('stream').Readable; const CoreCursor = require('./cursor'); const deprecate = require('util').deprecate; diff --git a/lib/bulk/common.js b/lib/bulk/common.js index 2da50744c5..1011f79f88 100644 --- a/lib/bulk/common.js +++ b/lib/bulk/common.js @@ -1,10 +1,10 @@ 'use strict'; -const Long = require('mongodb-core').BSON.Long; -const MongoError = require('mongodb-core').MongoError; -const ObjectID = require('mongodb-core').BSON.ObjectID; -const BSON = require('mongodb-core').BSON; -const MongoWriteConcernError = require('mongodb-core').MongoWriteConcernError; +const Long = require('../core').BSON.Long; +const MongoError = require('../core').MongoError; +const ObjectID = require('../core').BSON.ObjectID; +const BSON = require('../core').BSON; +const MongoWriteConcernError = require('../core').MongoWriteConcernError; const toError = require('../utils').toError; const handleCallback = require('../utils').handleCallback; const applyRetryableWrites = require('../utils').applyRetryableWrites; diff --git a/lib/change_stream.js b/lib/change_stream.js index e1d998dc78..10e0e34f1b 100644 --- a/lib/change_stream.js +++ b/lib/change_stream.js @@ -2,7 +2,7 @@ const EventEmitter = require('events'); const isResumableError = require('./error').isResumableError; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('./core').MongoError; const ReadConcern = require('./read_concern'); const MongoDBNamespace = require('./utils').MongoDBNamespace; diff --git a/lib/collection.js b/lib/collection.js index 77c2246996..524d0372b8 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -3,8 +3,8 @@ const deprecate = require('util').deprecate; const deprecateOptions = require('./utils').deprecateOptions; const checkCollectionName = require('./utils').checkCollectionName; -const ObjectID = require('mongodb-core').BSON.ObjectID; -const MongoError = require('mongodb-core').MongoError; +const ObjectID = require('./core').BSON.ObjectID; +const MongoError = require('./core').MongoError; const toError = require('./utils').toError; const handleCallback = require('./utils').handleCallback; const normalizeHintField = require('./utils').normalizeHintField; @@ -12,7 +12,7 @@ const decorateCommand = require('./utils').decorateCommand; const decorateWithCollation = require('./utils').decorateWithCollation; const decorateWithReadConcern = require('./utils').decorateWithReadConcern; const formattedOrderClause = require('./utils').formattedOrderClause; -const ReadPreference = require('mongodb-core').ReadPreference; +const ReadPreference = require('./core').ReadPreference; const unordered = require('./bulk/unordered'); const ordered = require('./bulk/ordered'); const ChangeStream = require('./change_stream'); diff --git a/lib/command_cursor.js b/lib/command_cursor.js index 456b97d813..ee4fbb1d94 100644 --- a/lib/command_cursor.js +++ b/lib/command_cursor.js @@ -1,8 +1,8 @@ 'use strict'; const inherits = require('util').inherits; -const ReadPreference = require('mongodb-core').ReadPreference; -const MongoError = require('mongodb-core').MongoError; +const ReadPreference = require('./core').ReadPreference; +const MongoError = require('./core').MongoError; const Readable = require('stream').Readable; const CoreCursor = require('./cursor'); const SUPPORTS = require('./utils').SUPPORTS; diff --git a/lib/core/cursor.js b/lib/core/cursor.js index 21eedd446a..efeaa7b983 100644 --- a/lib/core/cursor.js +++ b/lib/core/cursor.js @@ -24,33 +24,6 @@ const Long = BSON.Long; * allowing for iteration over the results returned from the underlying query. * * **CURSORS Cannot directly be instantiated** - * @example - * var Server = require('mongodb-core').Server - * , ReadPreference = require('mongodb-core').ReadPreference - * , assert = require('assert'); - * - * var server = new Server({host: 'localhost', port: 27017}); - * // Wait for the connection event - * server.on('connect', function(server) { - * assert.equal(null, err); - * - * // Execute the write - * var cursor = _server.cursor('integration_tests.inserts_example4', { - * find: 'integration_tests.example4' - * , query: {a:1} - * }, { - * readPreference: new ReadPreference('secondary'); - * }); - * - * // Get the first document - * cursor.next(function(err, doc) { - * assert.equal(null, err); - * server.destroy(); - * }); - * }); - * - * // Start connecting - * server.connect(); */ /** diff --git a/lib/core/index.js b/lib/core/index.js new file mode 100644 index 0000000000..623f669382 --- /dev/null +++ b/lib/core/index.js @@ -0,0 +1,50 @@ +'use strict'; + +let BSON = require('bson'); +const require_optional = require('require_optional'); +const EJSON = require('./utils').retrieveEJSON(); + +try { + // Attempt to grab the native BSON parser + const BSONNative = require_optional('bson-ext'); + // If we got the native parser, use it instead of the + // Javascript one + if (BSONNative) { + BSON = BSONNative; + } +} catch (err) {} // eslint-disable-line + +module.exports = { + // Errors + MongoError: require('./error').MongoError, + MongoNetworkError: require('./error').MongoNetworkError, + MongoParseError: require('./error').MongoParseError, + MongoTimeoutError: require('./error').MongoTimeoutError, + MongoWriteConcernError: require('./error').MongoWriteConcernError, + mongoErrorContextSymbol: require('./error').mongoErrorContextSymbol, + // Core + Connection: require('./connection/connection'), + Server: require('./topologies/server'), + ReplSet: require('./topologies/replset'), + Mongos: require('./topologies/mongos'), + Logger: require('./connection/logger'), + Cursor: require('./cursor'), + ReadPreference: require('./topologies/read_preference'), + Sessions: require('./sessions'), + BSON: BSON, + EJSON: EJSON, + Topology: require('./sdam/topology'), + // Raw operations + Query: require('./connection/commands').Query, + // Auth mechanisms + MongoCredentials: require('./auth/mongo_credentials').MongoCredentials, + defaultAuthProviders: require('./auth/defaultAuthProviders').defaultAuthProviders, + MongoCR: require('./auth/mongocr'), + X509: require('./auth/x509'), + Plain: require('./auth/plain'), + GSSAPI: require('./auth/gssapi'), + ScramSHA1: require('./auth/scram').ScramSHA1, + ScramSHA256: require('./auth/scram').ScramSHA256, + // Utilities + parseConnectionString: require('./uri_parser') +}; diff --git a/lib/core/topologies/mongos.js b/lib/core/topologies/mongos.js index 868af19b0d..e4551694bd 100644 --- a/lib/core/topologies/mongos.js +++ b/lib/core/topologies/mongos.js @@ -21,20 +21,6 @@ const BSON = retrieveBSON(); /** * @fileOverview The **Mongos** class is a class that represents a Mongos Proxy topology and is * used to construct connections. - * - * @example - * var Mongos = require('mongodb-core').Mongos - * , ReadPreference = require('mongodb-core').ReadPreference - * , assert = require('assert'); - * - * var server = new Mongos([{host: 'localhost', port: 30000}]); - * // Wait for the connection event - * server.on('connect', function(server) { - * server.destroy(); - * }); - * - * // Start connecting - * server.connect(); */ // diff --git a/lib/core/topologies/read_preference.js b/lib/core/topologies/read_preference.js index 58295bc33f..16ca30ab3d 100644 --- a/lib/core/topologies/read_preference.js +++ b/lib/core/topologies/read_preference.js @@ -8,29 +8,8 @@ * @param {array} tags The tags object * @param {object} [options] Additional read preference options * @param {number} [options.maxStalenessSeconds] Max secondary read staleness in seconds, Minimum value is 90 seconds. - * @return {ReadPreference} - * @example - * const ReplSet = require('mongodb-core').ReplSet, - * ReadPreference = require('mongodb-core').ReadPreference, - * assert = require('assert'); - * - * const server = new ReplSet([{host: 'localhost', port: 30000}], {setName: 'rs'}); - * // Wait for the connection event - * server.on('connect', function(server) { - * const cursor = server.cursor( - * 'db.test', - * { find: 'db.test', query: {} }, - * { readPreference: new ReadPreference('secondary') } - * ); - * - * cursor.next(function(err, doc) { - * server.destroy(); - * }); - * }); - * - * // Start connecting - * server.connect(); * @see https://docs.mongodb.com/manual/core/read-preference/ + * @return {ReadPreference} */ const ReadPreference = function(mode, tags, options) { // TODO(major): tags MUST be an array of tagsets diff --git a/lib/core/topologies/shared.js b/lib/core/topologies/shared.js index 6e6a2e0e74..5f39130d23 100644 --- a/lib/core/topologies/shared.js +++ b/lib/core/topologies/shared.js @@ -17,7 +17,7 @@ function emitSDAMEvent(self, event, description) { } // Get package.json variable -var driverVersion = require('../../package.json').version; +var driverVersion = require('../../../package.json').version; var nodejsversion = f('Node.js %s, %s', process.version, os.endianness()); var type = os.type(); var name = process.platform; diff --git a/lib/cursor.js b/lib/cursor.js index c35e7645cd..9fbd7415b8 100644 --- a/lib/cursor.js +++ b/lib/cursor.js @@ -7,11 +7,11 @@ const deprecate = require('util').deprecate; const handleCallback = require('./utils').handleCallback; const SUPPORTS = require('./utils').SUPPORTS; const MongoDBNamespace = require('./utils').MongoDBNamespace; -const ReadPreference = require('mongodb-core').ReadPreference; -const MongoError = require('mongodb-core').MongoError; +const ReadPreference = require('./core').ReadPreference; +const MongoError = require('./core').MongoError; const Readable = require('stream').Readable; -const CoreCursor = require('mongodb-core').Cursor; -const Map = require('mongodb-core').BSON.Map; +const CoreCursor = require('./core').Cursor; +const Map = require('./core').BSON.Map; const each = require('./operations/cursor_ops').each; @@ -57,7 +57,7 @@ const executeOperationV2 = require('./operations/execute_operation_v2'); */ /** - * Namespace provided by the mongodb-core and node.js + * Namespace provided by the code module * @external CoreCursor * @external Readable */ diff --git a/lib/db.js b/lib/db.js index 1ff1328ea1..c105eda00e 100644 --- a/lib/db.js +++ b/lib/db.js @@ -7,10 +7,10 @@ const CommandCursor = require('./command_cursor'); const handleCallback = require('./utils').handleCallback; const filterOptions = require('./utils').filterOptions; const toError = require('./utils').toError; -const ReadPreference = require('mongodb-core').ReadPreference; -const MongoError = require('mongodb-core').MongoError; -const ObjectID = require('mongodb-core').ObjectID; -const Logger = require('mongodb-core').Logger; +const ReadPreference = require('./core').ReadPreference; +const MongoError = require('./core').MongoError; +const ObjectID = require('./core').ObjectID; +const Logger = require('./core').Logger; const Collection = require('./collection'); const mergeOptionsAndWriteConcern = require('./utils').mergeOptionsAndWriteConcern; const executeOperation = require('./utils').executeOperation; diff --git a/lib/error.js b/lib/error.js index 03b555ad4c..03ef6485da 100644 --- a/lib/error.js +++ b/lib/error.js @@ -1,7 +1,7 @@ 'use strict'; -const MongoNetworkError = require('mongodb-core').MongoNetworkError; -const mongoErrorContextSymbol = require('mongodb-core').mongoErrorContextSymbol; +const MongoNetworkError = require('./core').MongoNetworkError; +const mongoErrorContextSymbol = require('./core').mongoErrorContextSymbol; const GET_MORE_NON_RESUMABLE_CODES = new Set([ 136, // CappedPositionLost diff --git a/lib/gridfs-stream/upload.js b/lib/gridfs-stream/upload.js index adbba4116b..3733f2cbfc 100644 --- a/lib/gridfs-stream/upload.js +++ b/lib/gridfs-stream/upload.js @@ -1,6 +1,6 @@ 'use strict'; -var core = require('mongodb-core'); +var core = require('../core'); var crypto = require('crypto'); var stream = require('stream'); var util = require('util'); diff --git a/lib/gridfs/chunk.js b/lib/gridfs/chunk.js index c29bba02a7..d276d72047 100644 --- a/lib/gridfs/chunk.js +++ b/lib/gridfs/chunk.js @@ -1,7 +1,7 @@ 'use strict'; -var Binary = require('mongodb-core').BSON.Binary, - ObjectID = require('mongodb-core').BSON.ObjectID; +var Binary = require('../core').BSON.Binary, + ObjectID = require('../core').BSON.ObjectID; var Buffer = require('safe-buffer').Buffer; diff --git a/lib/gridfs/grid_store.js b/lib/gridfs/grid_store.js index b5b19691f8..ed453111e3 100644 --- a/lib/gridfs/grid_store.js +++ b/lib/gridfs/grid_store.js @@ -36,13 +36,13 @@ * }); */ const Chunk = require('./chunk'); -const ObjectID = require('mongodb-core').BSON.ObjectID; -const ReadPreference = require('mongodb-core').ReadPreference; +const ObjectID = require('../core').BSON.ObjectID; +const ReadPreference = require('../core').ReadPreference; const Buffer = require('safe-buffer').Buffer; const fs = require('fs'); const f = require('util').format; const util = require('util'); -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const inherits = util.inherits; const Duplex = require('stream').Duplex; const shallowClone = require('../utils').shallowClone; @@ -56,7 +56,7 @@ const deprecationFn = deprecate(() => {}, 'GridStore is deprecated, and will be removed in a future version. Please use GridFSBucket instead'); /** - * Namespace provided by the mongodb-core and node.js + * Namespace provided by the core module * @external Duplex */ diff --git a/lib/mongo_client.js b/lib/mongo_client.js index 3a3ca02341..49d02981ed 100644 --- a/lib/mongo_client.js +++ b/lib/mongo_client.js @@ -5,7 +5,7 @@ const Db = require('./db'); const EventEmitter = require('events').EventEmitter; const executeOperation = require('./utils').executeOperation; const inherits = require('util').inherits; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('./core').MongoError; const deprecate = require('util').deprecate; const WriteConcern = require('./write_concern'); diff --git a/lib/operations/add_user.js b/lib/operations/add_user.js index 1383265664..5500a98331 100644 --- a/lib/operations/add_user.js +++ b/lib/operations/add_user.js @@ -8,8 +8,8 @@ const count = require('./collection_ops').count; const crypto = require('crypto'); const handleCallback = require('../utils').handleCallback; const loadDb = require('../dynamic_loaders').loadDb; -const MongoError = require('mongodb-core').MongoError; -const ReadPreference = require('mongodb-core').ReadPreference; +const MongoError = require('../core').MongoError; +const ReadPreference = require('../core').ReadPreference; const toError = require('../utils').toError; const updateOne = require('./collection_ops').updateOne; diff --git a/lib/operations/aggregate.js b/lib/operations/aggregate.js index eb0e503ade..57be1c8bb4 100644 --- a/lib/operations/aggregate.js +++ b/lib/operations/aggregate.js @@ -5,7 +5,7 @@ const applyWriteConcern = require('../utils').applyWriteConcern; const decorateWithCollation = require('../utils').decorateWithCollation; const decorateWithReadConcern = require('../utils').decorateWithReadConcern; const handleCallback = require('../utils').handleCallback; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const resolveReadPreference = require('../utils').resolveReadPreference; const toError = require('../utils').toError; diff --git a/lib/operations/aggregate_operation.js b/lib/operations/aggregate_operation.js index 6cbd9e977b..adf5035b35 100644 --- a/lib/operations/aggregate_operation.js +++ b/lib/operations/aggregate_operation.js @@ -6,7 +6,7 @@ const applyWriteConcern = require('../utils').applyWriteConcern; const decorateWithCollation = require('../utils').decorateWithCollation; const decorateWithReadConcern = require('../utils').decorateWithReadConcern; const handleCallback = require('../utils').handleCallback; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const resolveReadPreference = require('../utils').resolveReadPreference; const toError = require('../utils').toError; diff --git a/lib/operations/bulk_write.js b/lib/operations/bulk_write.js index 559e15a3eb..8f14f0217c 100644 --- a/lib/operations/bulk_write.js +++ b/lib/operations/bulk_write.js @@ -2,7 +2,7 @@ const applyRetryableWrites = require('../utils').applyRetryableWrites; const applyWriteConcern = require('../utils').applyWriteConcern; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const OperationBase = require('./operation').OperationBase; class BulkWriteOperation extends OperationBase { diff --git a/lib/operations/collection_ops.js b/lib/operations/collection_ops.js index 67098bdc69..6ab8d4435b 100644 --- a/lib/operations/collection_ops.js +++ b/lib/operations/collection_ops.js @@ -3,7 +3,7 @@ const applyWriteConcern = require('../utils').applyWriteConcern; const applyRetryableWrites = require('../utils').applyRetryableWrites; const checkCollectionName = require('../utils').checkCollectionName; -const Code = require('mongodb-core').BSON.Code; +const Code = require('../core').BSON.Code; const createIndexDb = require('./db_ops').createIndex; const decorateWithCollation = require('../utils').decorateWithCollation; const decorateWithReadConcern = require('../utils').decorateWithReadConcern; @@ -15,9 +15,9 @@ const formattedOrderClause = require('../utils').formattedOrderClause; const resolveReadPreference = require('../utils').resolveReadPreference; const handleCallback = require('../utils').handleCallback; const indexInformationDb = require('./db_ops').indexInformation; -const Long = require('mongodb-core').BSON.Long; -const MongoError = require('mongodb-core').MongoError; -const ReadPreference = require('mongodb-core').ReadPreference; +const Long = require('../core').BSON.Long; +const MongoError = require('../core').MongoError; +const ReadPreference = require('../core').ReadPreference; const toError = require('../utils').toError; let collection; diff --git a/lib/operations/command.js b/lib/operations/command.js index 101560a91a..f18059212e 100644 --- a/lib/operations/command.js +++ b/lib/operations/command.js @@ -3,7 +3,7 @@ const OperationBase = require('./operation').OperationBase; const debugOptions = require('../utils').debugOptions; const handleCallback = require('../utils').handleCallback; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const resolveReadPreference = require('../utils').resolveReadPreference; const MongoDBNamespace = require('../utils').MongoDBNamespace; diff --git a/lib/operations/common_functions.js b/lib/operations/common_functions.js index 037a7cfc50..135763dacd 100644 --- a/lib/operations/common_functions.js +++ b/lib/operations/common_functions.js @@ -8,8 +8,8 @@ const executeCommand = require('./db_ops').executeCommand; const formattedOrderClause = require('../utils').formattedOrderClause; const handleCallback = require('../utils').handleCallback; const loadCursor = require('../dynamic_loaders').loadCursor; -const MongoError = require('mongodb-core').MongoError; -const ReadPreference = require('mongodb-core').ReadPreference; +const MongoError = require('../core').MongoError; +const ReadPreference = require('../core').ReadPreference; const toError = require('../utils').toError; /** diff --git a/lib/operations/connect.js b/lib/operations/connect.js index 3c643ee385..fbb88be62c 100644 --- a/lib/operations/connect.js +++ b/lib/operations/connect.js @@ -3,17 +3,17 @@ const OperationBase = require('./operation').OperationBase; const Aspect = require('./operation').Aspect; const deprecate = require('util').deprecate; -const Logger = require('mongodb-core').Logger; -const MongoCredentials = require('mongodb-core').MongoCredentials; -const MongoError = require('mongodb-core').MongoError; +const Logger = require('../core').Logger; +const MongoCredentials = require('../core').MongoCredentials; +const MongoError = require('../core').MongoError; const Mongos = require('../topologies/mongos'); const NativeTopology = require('../topologies/native_topology'); -const parse = require('mongodb-core').parseConnectionString; +const parse = require('../core').parseConnectionString; const ReadConcern = require('../read_concern'); -const ReadPreference = require('mongodb-core').ReadPreference; +const ReadPreference = require('../core').ReadPreference; const ReplSet = require('../topologies/replset'); const Server = require('../topologies/server'); -const ServerSessionPool = require('mongodb-core').Sessions.ServerSessionPool; +const ServerSessionPool = require('../core').Sessions.ServerSessionPool; let client; function loadClient() { diff --git a/lib/operations/create_collection.js b/lib/operations/create_collection.js index 6841f11eef..daeb4be44c 100644 --- a/lib/operations/create_collection.js +++ b/lib/operations/create_collection.js @@ -5,8 +5,8 @@ const CommandOperation = require('./command'); const applyWriteConcern = require('../utils').applyWriteConcern; const handleCallback = require('../utils').handleCallback; const loadCollection = require('../dynamic_loaders').loadCollection; -const MongoError = require('mongodb-core').MongoError; -const ReadPreference = require('mongodb-core').ReadPreference; +const MongoError = require('../core').MongoError; +const ReadPreference = require('../core').ReadPreference; // Filter out any write concern options const illegalCommandFields = [ diff --git a/lib/operations/create_index.js b/lib/operations/create_index.js index 9fe4652b4d..7f0d542e67 100644 --- a/lib/operations/create_index.js +++ b/lib/operations/create_index.js @@ -5,9 +5,9 @@ const applyWriteConcern = require('../utils').applyWriteConcern; const CommandOperation = require('./command'); const CONSTANTS = require('../constants'); const handleCallback = require('../utils').handleCallback; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const parseIndexOptions = require('../utils').parseIndexOptions; -const ReadPreference = require('mongodb-core').ReadPreference; +const ReadPreference = require('../core').ReadPreference; const toError = require('../utils').toError; class CreateIndexOperation extends OperationBase { diff --git a/lib/operations/create_indexes.js b/lib/operations/create_indexes.js index 93d6aedf9c..daf76c34e6 100644 --- a/lib/operations/create_indexes.js +++ b/lib/operations/create_indexes.js @@ -2,8 +2,8 @@ const OperationBase = require('./operation').OperationBase; const executeCommand = require('./db_ops').executeCommand; -const MongoError = require('mongodb-core').MongoError; -const ReadPreference = require('mongodb-core').ReadPreference; +const MongoError = require('../core').MongoError; +const ReadPreference = require('../core').ReadPreference; class CreateIndexesOperation extends OperationBase { constructor(collection, indexSpecs, options) { diff --git a/lib/operations/cursor_ops.js b/lib/operations/cursor_ops.js index c33192b1c7..4731352474 100644 --- a/lib/operations/cursor_ops.js +++ b/lib/operations/cursor_ops.js @@ -3,7 +3,7 @@ const buildCountCommand = require('./collection_ops').buildCountCommand; const formattedOrderClause = require('../utils').formattedOrderClause; const handleCallback = require('../utils').handleCallback; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const push = Array.prototype.push; let cursor; diff --git a/lib/operations/db_ops.js b/lib/operations/db_ops.js index c674bc208c..210fe1191c 100644 --- a/lib/operations/db_ops.js +++ b/lib/operations/db_ops.js @@ -1,14 +1,14 @@ 'use strict'; const applyWriteConcern = require('../utils').applyWriteConcern; -const Code = require('mongodb-core').BSON.Code; +const Code = require('../core').BSON.Code; const resolveReadPreference = require('../utils').resolveReadPreference; const crypto = require('crypto'); const debugOptions = require('../utils').debugOptions; const handleCallback = require('../utils').handleCallback; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const parseIndexOptions = require('../utils').parseIndexOptions; -const ReadPreference = require('mongodb-core').ReadPreference; +const ReadPreference = require('../core').ReadPreference; const toError = require('../utils').toError; const CONSTANTS = require('../constants'); const MongoDBNamespace = require('../utils').MongoDBNamespace; diff --git a/lib/operations/drop_collection.js b/lib/operations/drop_collection.js index a09db5616c..2b0c4b8a27 100644 --- a/lib/operations/drop_collection.js +++ b/lib/operations/drop_collection.js @@ -2,7 +2,7 @@ const CommandOperation = require('./command'); const handleCallback = require('../utils').handleCallback; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; class DropCollectionOperation extends CommandOperation { constructor(db, command, options) { diff --git a/lib/operations/drop_database.js b/lib/operations/drop_database.js index 8205abde33..0f2c460be9 100644 --- a/lib/operations/drop_database.js +++ b/lib/operations/drop_database.js @@ -2,7 +2,7 @@ const CommandOperation = require('./command'); const handleCallback = require('../utils').handleCallback; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; class DropDatabaseOperation extends CommandOperation { constructor(db, command, options) { diff --git a/lib/operations/execute_db_admin_command.js b/lib/operations/execute_db_admin_command.js index a96aac4538..d15fc8e660 100644 --- a/lib/operations/execute_db_admin_command.js +++ b/lib/operations/execute_db_admin_command.js @@ -2,7 +2,7 @@ const OperationBase = require('./operation').OperationBase; const handleCallback = require('../utils').handleCallback; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const MongoDBNamespace = require('../utils').MongoDBNamespace; class ExecuteDbAdminCommandOperation extends OperationBase { diff --git a/lib/operations/execute_operation_v2.js b/lib/operations/execute_operation_v2.js index 09d187d9bf..0578fc9bee 100644 --- a/lib/operations/execute_operation_v2.js +++ b/lib/operations/execute_operation_v2.js @@ -1,6 +1,6 @@ 'use strict'; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const Aspect = require('./operation').Aspect; const OperationBase = require('./operation').OperationBase; diff --git a/lib/operations/explain.js b/lib/operations/explain.js index 9acd702657..8c861c914c 100644 --- a/lib/operations/explain.js +++ b/lib/operations/explain.js @@ -1,7 +1,7 @@ 'use strict'; const Aspect = require('./operation').Aspect; -const CoreCursor = require('mongodb-core').Cursor; +const CoreCursor = require('../core').Cursor; const defineAspects = require('./operation').defineAspects; const OperationBase = require('./operation').OperationBase; diff --git a/lib/operations/find_and_modify.js b/lib/operations/find_and_modify.js index f43e460e6d..8965eb4857 100644 --- a/lib/operations/find_and_modify.js +++ b/lib/operations/find_and_modify.js @@ -7,7 +7,7 @@ const decorateWithCollation = require('../utils').decorateWithCollation; const executeCommand = require('./db_ops').executeCommand; const formattedOrderClause = require('../utils').formattedOrderClause; const handleCallback = require('../utils').handleCallback; -const ReadPreference = require('mongodb-core').ReadPreference; +const ReadPreference = require('../core').ReadPreference; class FindAndModifyOperation extends OperationBase { constructor(collection, query, sort, doc, options) { diff --git a/lib/operations/insert_many.js b/lib/operations/insert_many.js index f0236dc565..460a535d66 100644 --- a/lib/operations/insert_many.js +++ b/lib/operations/insert_many.js @@ -2,7 +2,7 @@ const OperationBase = require('./operation').OperationBase; const BulkWriteOperation = require('./bulk_write'); -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const prepareDocs = require('./common_functions').prepareDocs; class InsertManyOperation extends OperationBase { diff --git a/lib/operations/insert_one.js b/lib/operations/insert_one.js index 3b926e11ee..8f7f85a885 100644 --- a/lib/operations/insert_one.js +++ b/lib/operations/insert_one.js @@ -3,7 +3,7 @@ const applyRetryableWrites = require('../utils').applyRetryableWrites; const applyWriteConcern = require('../utils').applyWriteConcern; const handleCallback = require('../utils').handleCallback; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const OperationBase = require('./operation').OperationBase; const prepareDocs = require('./common_functions').prepareDocs; const toError = require('../utils').toError; diff --git a/lib/operations/list_indexes.js b/lib/operations/list_indexes.js index 0b33a206af..f44d810f61 100644 --- a/lib/operations/list_indexes.js +++ b/lib/operations/list_indexes.js @@ -2,7 +2,7 @@ const OperationBase = require('./operation').OperationBase; const CommandCursor = require('../command_cursor'); -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const resolveReadPreference = require('../utils').resolveReadPreference; class ListIndexesOperation extends OperationBase { diff --git a/lib/operations/map_reduce.js b/lib/operations/map_reduce.js index 6bc2257647..69b3cb509f 100644 --- a/lib/operations/map_reduce.js +++ b/lib/operations/map_reduce.js @@ -1,7 +1,7 @@ 'use strict'; const applyWriteConcern = require('../utils').applyWriteConcern; -const Code = require('mongodb-core').BSON.Code; +const Code = require('../core').BSON.Code; const decorateWithCollation = require('../utils').decorateWithCollation; const decorateWithReadConcern = require('../utils').decorateWithReadConcern; const executeCommand = require('./db_ops').executeCommand; diff --git a/lib/operations/mongo_client_ops.js b/lib/operations/mongo_client_ops.js index 518e907f15..4116c2590f 100644 --- a/lib/operations/mongo_client_ops.js +++ b/lib/operations/mongo_client_ops.js @@ -1,16 +1,16 @@ 'use strict'; const deprecate = require('util').deprecate; -const Logger = require('mongodb-core').Logger; -const MongoError = require('mongodb-core').MongoError; +const Logger = require('../core').Logger; +const MongoError = require('../core').MongoError; const Mongos = require('../topologies/mongos'); -const parse = require('mongodb-core').parseConnectionString; -const ReadPreference = require('mongodb-core').ReadPreference; +const parse = require('../core').parseConnectionString; +const ReadPreference = require('../core').ReadPreference; const ReplSet = require('../topologies/replset'); const Server = require('../topologies/server'); -const ServerSessionPool = require('mongodb-core').Sessions.ServerSessionPool; +const ServerSessionPool = require('../core').Sessions.ServerSessionPool; const NativeTopology = require('../topologies/native_topology'); -const MongoCredentials = require('mongodb-core').MongoCredentials; +const MongoCredentials = require('../core').MongoCredentials; const ReadConcern = require('../read_concern'); let client; diff --git a/lib/operations/options_operation.js b/lib/operations/options_operation.js index b506a00f4e..9a739a5193 100644 --- a/lib/operations/options_operation.js +++ b/lib/operations/options_operation.js @@ -2,7 +2,7 @@ const OperationBase = require('./operation').OperationBase; const handleCallback = require('../utils').handleCallback; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; class OptionsOperation extends OperationBase { constructor(collection, options) { diff --git a/lib/operations/remove_user.js b/lib/operations/remove_user.js index d44bc5dd50..8018ba0076 100644 --- a/lib/operations/remove_user.js +++ b/lib/operations/remove_user.js @@ -7,8 +7,8 @@ const CONSTANTS = require('../constants'); const findOne = require('./collection_ops').findOne; const handleCallback = require('../utils').handleCallback; const loadDb = require('../dynamic_loaders').loadDb; -const MongoError = require('mongodb-core').MongoError; -const ReadPreference = require('mongodb-core').ReadPreference; +const MongoError = require('../core').MongoError; +const ReadPreference = require('../core').ReadPreference; const remove = require('./collection_ops').remove; class RemoveUserOperation extends OperationBase { diff --git a/lib/topologies/mongos.js b/lib/topologies/mongos.js index ae2ad8e758..ccec17961f 100644 --- a/lib/topologies/mongos.js +++ b/lib/topologies/mongos.js @@ -1,8 +1,8 @@ 'use strict'; const TopologyBase = require('./topology_base').TopologyBase; -const MongoError = require('mongodb-core').MongoError; -const CMongos = require('mongodb-core').Mongos; +const MongoError = require('../core').MongoError; +const CMongos = require('../core').Mongos; const Cursor = require('../cursor'); const Server = require('./server'); const Store = require('./topology_base').Store; @@ -165,7 +165,7 @@ class Mongos extends TopologyBase { ? options.socketOptions : options; - // Translate all the options to the mongodb-core ones + // Translate all the options to the core types clonedOptions = translateOptions(clonedOptions, socketOptions); // Build default client information diff --git a/lib/topologies/native_topology.js b/lib/topologies/native_topology.js index 0bd31dc202..51574878d7 100644 --- a/lib/topologies/native_topology.js +++ b/lib/topologies/native_topology.js @@ -1,6 +1,6 @@ 'use strict'; -const Topology = require('mongodb-core').Topology; +const Topology = require('../core').Topology; const ServerCapabilities = require('./topology_base').ServerCapabilities; const Cursor = require('../cursor'); const translateOptions = require('../utils').translateOptions; @@ -30,7 +30,7 @@ class NativeTopology extends Topology { ? options.socketOptions : options; - // Translate all the options to the mongodb-core ones + // Translate all the options to the core types clonedOptions = translateOptions(clonedOptions, socketOptions); super(servers, clonedOptions); diff --git a/lib/topologies/replset.js b/lib/topologies/replset.js index 1872a4b305..700a0b7abc 100644 --- a/lib/topologies/replset.js +++ b/lib/topologies/replset.js @@ -2,10 +2,10 @@ const Server = require('./server'); const Cursor = require('../cursor'); -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const TopologyBase = require('./topology_base').TopologyBase; const Store = require('./topology_base').Store; -const CReplSet = require('mongodb-core').ReplSet; +const CReplSet = require('../core').ReplSet; const MAX_JS_INT = require('../utils').MAX_JS_INT; const translateOptions = require('../utils').translateOptions; const filterOptions = require('../utils').filterOptions; @@ -172,7 +172,7 @@ class ReplSet extends TopologyBase { ? options.socketOptions : options; - // Translate all the options to the mongodb-core ones + // Translate all the options to the core types clonedOptions = translateOptions(clonedOptions, socketOptions); // Build default client information diff --git a/lib/topologies/server.js b/lib/topologies/server.js index 6f79d57416..838bbbd712 100644 --- a/lib/topologies/server.js +++ b/lib/topologies/server.js @@ -1,10 +1,10 @@ 'use strict'; -const CServer = require('mongodb-core').Server; +const CServer = require('../core').Server; const Cursor = require('../cursor'); const TopologyBase = require('./topology_base').TopologyBase; const Store = require('./topology_base').Store; -const MongoError = require('mongodb-core').MongoError; +const MongoError = require('../core').MongoError; const MAX_JS_INT = require('../utils').MAX_JS_INT; const translateOptions = require('../utils').translateOptions; const filterOptions = require('../utils').filterOptions; @@ -165,7 +165,7 @@ class Server extends TopologyBase { ? options.socketOptions : options; - // Translate all the options to the mongodb-core ones + // Translate all the options to the core types clonedOptions = translateOptions(clonedOptions, socketOptions); // Build default client information @@ -177,7 +177,7 @@ class Server extends TopologyBase { // Define the internal properties this.s = { - // Create an instance of a server instance from mongodb-core + // Create an instance of a server instance from core module coreTopology: new CServer(clonedOptions), // Server capabilities sCapabilities: null, diff --git a/lib/topologies/topology_base.js b/lib/topologies/topology_base.js index 8467ccbe0f..3461c5311c 100644 --- a/lib/topologies/topology_base.js +++ b/lib/topologies/topology_base.js @@ -1,11 +1,11 @@ 'use strict'; const EventEmitter = require('events'), - MongoError = require('mongodb-core').MongoError, + MongoError = require('../core').MongoError, f = require('util').format, os = require('os'), translateReadPreference = require('../utils').translateReadPreference, - ClientSession = require('mongodb-core').Sessions.ClientSession; + ClientSession = require('../core').Sessions.ClientSession; // The store of ops var Store = function(topology, storeOptions) { diff --git a/lib/url_parser.js b/lib/url_parser.js index 2c1660890b..c0f10b467d 100644 --- a/lib/url_parser.js +++ b/lib/url_parser.js @@ -1,9 +1,9 @@ 'use strict'; -const ReadPreference = require('mongodb-core').ReadPreference, +const ReadPreference = require('./core').ReadPreference, parser = require('url'), f = require('util').format, - Logger = require('mongodb-core').Logger, + Logger = require('./core').Logger, dns = require('dns'); const ReadConcern = require('./read_concern'); diff --git a/lib/utils.js b/lib/utils.js index 3ab6b53b8c..4729df2782 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,7 +1,7 @@ 'use strict'; -const MongoError = require('mongodb-core').MongoError; -const ReadPreference = require('mongodb-core').ReadPreference; +const MongoError = require('./core').MongoError; +const ReadPreference = require('./core').ReadPreference; const WriteConcern = require('./write_concern'); var shallowClone = function(obj) { diff --git a/package-lock.json b/package-lock.json index 51de5e1ead..4b312b01b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3454,6 +3454,7 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "dev": true, "optional": true }, "meow": { @@ -3692,16 +3693,6 @@ "integrity": "sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw==", "dev": true }, - "mongodb-core": { - "version": "github:mongodb-js/mongodb-core#0587cde75944db46a6318d224d9d99379d905130", - "from": "github:mongodb-js/mongodb-core#next", - "requires": { - "bson": "^1.1.1", - "require_optional": "^1.0.1", - "safe-buffer": "^5.1.2", - "saslprep": "^1.0.0" - } - }, "mongodb-download-url": { "version": "0.4.2", "resolved": "https://registry.npmjs.org/mongodb-download-url/-/mongodb-download-url-0.4.2.tgz", @@ -4712,6 +4703,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.2.tgz", "integrity": "sha512-4cDsYuAjXssUSjxHKRe4DTZC0agDwsCqcMqtJAQPzC74nJ7LfAJflAtC1Zed5hMzEQKj82d3tuzqdGNRsLJ4Gw==", + "dev": true, "optional": true, "requires": { "sparse-bitfield": "^3.0.3" @@ -4879,6 +4871,7 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", "integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=", + "dev": true, "optional": true, "requires": { "memory-pager": "^1.0.2" @@ -5554,6 +5547,12 @@ "mkdirp": "^0.5.1" } }, + "wtfnode": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/wtfnode/-/wtfnode-0.8.0.tgz", + "integrity": "sha512-A5jm/0REykxUac1q4Q5kv+hDIiacvqVpwIoXzCQcRL7syeEKucVVOxyLLrt+jIiZoXfla3lnsxUw/cmWXIaGWA==", + "dev": true + }, "xmlcreate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-1.0.2.tgz", diff --git a/package.json b/package.json index 344845c5cf..0eae765b00 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,15 @@ "driver", "official" ], + "peerOptionalDependencies": { + "kerberos": "^1.0.0", + "mongodb-extjson": "^2.1.2", + "snappy": "^6.1.1", + "bson-ext": "^2.0.0" + }, "dependencies": { - "mongodb-core": "mongodb-js/mongodb-core#next", + "bson": "^1.1.1", + "require_optional": "^1.0.1", "safe-buffer": "^5.1.2" }, "devDependencies": { @@ -41,7 +48,8 @@ "sinon": "^4.3.0", "sinon-chai": "^3.2.0", "standard-version": "^4.4.0", - "worker-farm": "^1.5.0" + "worker-farm": "^1.5.0", + "wtfnode": "^0.8.0" }, "license": "Apache-2.0", "engines": { @@ -52,8 +60,8 @@ }, "scripts": { "atlas": "node ./test/atlas_connectivity_tests.js", - "test": "npm run lint && mongodb-test-runner -t 60000 test/unit test/functional", - "coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/unit test/functional", + "test": "npm run lint && mongodb-test-runner -t 60000 test/core test/unit test/functional", + "coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/core test/unit test/functional", "lint": "eslint lib test", "format": "prettier --print-width 100 --tab-width 2 --single-quote --write 'test/**/*.js' 'lib/**/*.js'", "bench": "node test/driverBench/", diff --git a/test/config.js b/test/config.js index cea68f1b34..f8a730d83c 100644 --- a/test/config.js +++ b/test/config.js @@ -3,6 +3,8 @@ const ConfigurationBase = require('mongodb-test-runner').ConfigurationBase; const f = require('util').format; const url = require('url'); const qs = require('querystring'); +const core = require('../lib/core'); + class NativeConfiguration extends ConfigurationBase { constructor(environment) { super(environment); @@ -16,14 +18,19 @@ class NativeConfiguration extends ConfigurationBase { } } - defaultTopology(serverHost, serverPort, serverOpts, _mongo) { - return new _mongo.Server(serverHost, serverPort, serverOpts || {}); - } - usingUnifiedTopology() { return !!process.env.MONGODB_UNIFIED_TOPOLOGY; } + defaultTopology(host, port, serverOptions) { + const options = Object.assign({}, { host, port }, serverOptions); + if (this.usingUnifiedTopology()) { + return new core.Topology(options); + } + + return new core.Server(options); + } + start(callback) { const self = this; if (this.skipStart) return callback(); @@ -108,6 +115,41 @@ class NativeConfiguration extends ConfigurationBase { return new this.mongo.MongoClient(connectionString, serverOptions); } + newTopology(host, port, options) { + host = host || 'localhost'; + port = port || 27017; + options = options || {}; + return this.topology(host, port, options); + } + + newConnection(host, port, options, callback) { + if (typeof options === 'function') { + callback = options; + options = {}; + } + + var server = this.topology(host, port, options); + var errorHandler = function(err) { + callback(err); + }; + + // Set up connect + server.once('connect', function() { + server.removeListener('error', errorHandler); + callback(null, server); + }); + + server.once('error', errorHandler); + + // Connect + try { + server.connect(); + } catch (err) { + server.removeListener('error', errorHandler); + callback(err); + } + } + url(username, password) { const url = this.options.url || 'mongodb://%slocalhost:27017/' + this.db; diff --git a/test/core/functional/basic_replset_server_auth_tests.js b/test/core/functional/basic_replset_server_auth_tests.js index 7d2a587075..17846ced65 100644 --- a/test/core/functional/basic_replset_server_auth_tests.js +++ b/test/core/functional/basic_replset_server_auth_tests.js @@ -4,10 +4,10 @@ var expect = require('chai').expect, f = require('util').format, locateAuthMethod = require('./shared').locateAuthMethod, executeCommand = require('./shared').executeCommand, - ReplSet = require('../../../lib/topologies/replset'), - Connection = require('../../../lib/connection/connection'); + ReplSet = require('../../../lib/core/topologies/replset'), + Connection = require('../../../lib/core/connection/connection'); -const MongoCredentials = require('../../../lib/auth/mongo_credentials').MongoCredentials; +const MongoCredentials = require('../../../lib/core/auth/mongo_credentials').MongoCredentials; var setUp = function(configuration, options, callback) { var ReplSetManager = require('mongodb-topology-manager').ReplSet; diff --git a/test/core/functional/basic_single_server_auth_tests.js b/test/core/functional/basic_single_server_auth_tests.js index f6a33bc336..4ef4ff0ae1 100644 --- a/test/core/functional/basic_single_server_auth_tests.js +++ b/test/core/functional/basic_single_server_auth_tests.js @@ -3,10 +3,10 @@ var expect = require('chai').expect, locateAuthMethod = require('./shared').locateAuthMethod, executeCommand = require('./shared').executeCommand, - Connection = require('../../../lib/connection/connection'), + Connection = require('../../../lib/core/connection/connection'), Bson = require('bson'); -const MongoCredentials = require('../../../lib/auth/mongo_credentials').MongoCredentials; +const MongoCredentials = require('../../../lib/core/auth/mongo_credentials').MongoCredentials; describe('Basic single server auth tests', function() { it('should correctly authenticate server using scram-sha-256 using connect auth', { @@ -43,9 +43,7 @@ describe('Basic single server auth tests', function() { expect(cmdErr).to.be.null; expect(r).to.exist; - const server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + const server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson() }); @@ -100,11 +98,13 @@ describe('Basic single server auth tests', function() { expect(r).to.exist; expect(cmdErr).to.be.null; - var server = this.configuration.newTopology({ - host: self.configuration.host, - port: self.configuration.port, - bson: new Bson() - }); + var server = this.configuration.newTopology( + this.configuration.host, + this.configuration.port, + { + bson: new Bson() + } + ); server.on('error', function() { // console.log('=================== ' + Object.keys(Connection.connections()).length) @@ -150,9 +150,7 @@ describe('Basic single server auth tests', function() { expect(r).to.exist; expect(cmdErr).to.be.null; - var server = config.newTopology({ - host: self.configuration.host, - port: self.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson() }); @@ -242,11 +240,13 @@ describe('Basic single server auth tests', function() { expect(createUserErr).to.be.null; // Attempt to connect - var server = config.newTopology({ - host: self.configuration.host, - port: self.configuration.port, - bson: new Bson() - }); + var server = config.newTopology( + this.configuration.host, + this.configuration.port, + { + bson: new Bson() + } + ); var index = 0; @@ -347,11 +347,13 @@ describe('Basic single server auth tests', function() { expect(createUserErr).to.be.null; // Attempt to connect - var server = config.newTopology({ - host: self.configuration.host, - port: self.configuration.port, - bson: new Bson() - }); + var server = config.newTopology( + this.configuration.host, + this.configuration.port, + { + bson: new Bson() + } + ); var index = 0; var error = false; @@ -466,11 +468,13 @@ describe('Basic single server auth tests', function() { expect(createUserErr).to.be.null; // Attempt to connect - var server = config.newTopology({ - host: self.configuration.host, - port: self.configuration.port, - bson: new Bson() - }); + var server = config.newTopology( + this.configuration.host, + this.configuration.port, + { + bson: new Bson() + } + ); // Add event listeners server.on('connect', function(_server) { @@ -560,11 +564,13 @@ describe('Basic single server auth tests', function() { expect(createUserRes).to.exist; expect(createUserErr).to.be.null; // Attempt to connect - var server = config.newTopology({ - host: self.configuration.host, - port: self.configuration.port, - bson: new Bson() - }); + var server = config.newTopology( + this.configuration.host, + this.configuration.port, + { + bson: new Bson() + } + ); // Add event listeners server.on('connect', function(_server) { diff --git a/test/core/functional/client_metadata_tests.js b/test/core/functional/client_metadata_tests.js index 5d562d535b..e26fa38c41 100644 --- a/test/core/functional/client_metadata_tests.js +++ b/test/core/functional/client_metadata_tests.js @@ -1,8 +1,11 @@ 'use strict'; -var expect = require('chai').expect, - Bson = require('bson'), - Mongos = require('../../../lib/topologies/mongos'); +const expect = require('chai').expect; + +const core = require('../../../lib/core'); +const BSON = core.BSON; +const Mongos = core.Mongos; +const ReplSet = core.ReplSet; describe('Client metadata tests', function() { it('should correctly pass the configuration settings to server', { @@ -10,12 +13,14 @@ describe('Client metadata tests', function() { test: function(done) { // Attempt to connect - var server = this.configuration.newTopology({ - host: this.configuration.host, - port: this.configuration.port, - bson: new Bson(), - appname: 'My application name' - }); + var server = this.configuration.newTopology( + this.configuration.host, + this.configuration.port, + { + bson: new BSON(), + appname: 'My application name' + } + ); expect(server.clientInfo.application.name).to.equal('My application name'); done(); @@ -27,10 +32,8 @@ describe('Client metadata tests', function() { metadata: { requires: { topology: 'replicaset' } }, test: function(done) { - var self = this; - - var ReplSet = this.configuration.mongo.ReplSet, - manager = this.configuration.manager; + const self = this; + const manager = this.configuration.manager; // Get the primary server manager.primary().then(function(_manager) { diff --git a/test/core/functional/connection_tests.js b/test/core/functional/connection_tests.js index b23a231024..4c829ebc11 100644 --- a/test/core/functional/connection_tests.js +++ b/test/core/functional/connection_tests.js @@ -3,7 +3,7 @@ const bson = require('bson'); const expect = require('chai').expect; const mock = require('mongodb-mock-server'); -const Connection = require('../../../lib/connection/connection'); +const Connection = require('../../../lib/core/connection/connection'); describe('Connection', function() { const noop = () => {}; diff --git a/test/core/functional/cursor_tests.js b/test/core/functional/cursor_tests.js index 0a7d0036c4..2444edfe16 100644 --- a/test/core/functional/cursor_tests.js +++ b/test/core/functional/cursor_tests.js @@ -484,7 +484,7 @@ describe('Cursor tests', function() { // metadata: { requires: { topology: ['single'] } }, // test: function(done) { // var configuration = this.configuration, - // Server = require('../../../lib/topologies/server'), + // Server = require('../../../lib/core/topologies/server'), // bson = require('bson'); // // Attempt to connect diff --git a/test/core/functional/error_tests.js b/test/core/functional/error_tests.js index d1b3704cfe..b5409568f8 100644 --- a/test/core/functional/error_tests.js +++ b/test/core/functional/error_tests.js @@ -38,7 +38,7 @@ describe('Error tests', function() { }, test: function(done) { - var MongoError = require('../../../lib/error.js').MongoError; + var MongoError = require('../../../lib/core/error.js').MongoError; var errorMessage = 'A test error'; var err = new MongoError(errorMessage); @@ -56,7 +56,7 @@ describe('Error tests', function() { }, test: function(done) { - var MongoError = require('../../../lib/error.js').MongoError; + var MongoError = require('../../../lib/core/error.js').MongoError; var errorMessage = 'A test error'; var err = new MongoError(new Error(errorMessage)); @@ -74,7 +74,7 @@ describe('Error tests', function() { }, test: function(done) { - var MongoError = require('../../../lib/error.js').MongoError; + var MongoError = require('../../../lib/core/error.js').MongoError; var errorMessage = 'A test error'; var err = new MongoError({ message: errorMessage, someData: 12345 }); @@ -93,7 +93,7 @@ describe('Error tests', function() { }, test: function(done) { - var errors = require('../../../lib/error'); + var errors = require('../../../lib/core/error'); var errorMessage = 'A test error'; var err = new errors.MongoNetworkError(errorMessage); diff --git a/test/core/functional/extend_cursor_tests.js b/test/core/functional/extend_cursor_tests.js index 32fcb30d41..d9318afbba 100644 --- a/test/core/functional/extend_cursor_tests.js +++ b/test/core/functional/extend_cursor_tests.js @@ -1,8 +1,9 @@ 'use strict'; -var expect = require('chai').expect, - inherits = require('util').inherits, - f = require('util').format; +const expect = require('chai').expect; +const inherits = require('util').inherits; +const f = require('util').format; +const CoreCursor = require('../../../lib/core/cursor'); describe('Extend cursor tests', function() { it('should correctly extend the cursor with custom implementation', { @@ -13,11 +14,10 @@ describe('Extend cursor tests', function() { test: function(done) { var self = this; const config = this.configuration; - var Cursor = this.configuration.mongo.Cursor; // Create an extended cursor that adds a toArray function var ExtendedCursor = function() { - Cursor.apply(this, Array.prototype.slice.call(arguments, 0)); + CoreCursor.apply(this, Array.prototype.slice.call(arguments, 0)); var extendedCursorSelf = this; // Resolve all the next @@ -42,12 +42,10 @@ describe('Extend cursor tests', function() { }; // Extend the Cursor - inherits(ExtendedCursor, Cursor); + inherits(ExtendedCursor, CoreCursor); // Attempt to connect, adding a custom cursor creator - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { cursorFactory: ExtendedCursor }); diff --git a/test/core/functional/max_staleness_tests.js b/test/core/functional/max_staleness_tests.js index 2edd29b389..fcb415c404 100644 --- a/test/core/functional/max_staleness_tests.js +++ b/test/core/functional/max_staleness_tests.js @@ -4,10 +4,10 @@ const expect = require('chai').expect, p = require('path'), f = require('util').format, fs = require('fs'), - Server = require('../../../lib/topologies/server'), - ReplSetState = require('../../../lib/topologies/replset_state'), - MongoError = require('../../../lib/error').MongoError, - ReadPreference = require('../../../lib/topologies/read_preference'); + Server = require('../../../lib/core/topologies/server'), + ReplSetState = require('../../../lib/core/topologies/replset_state'), + MongoError = require('../../../lib/core/error').MongoError, + ReadPreference = require('../../../lib/core/topologies/read_preference'); const rsWithPrimaryPath = f('%s/../spec/max-staleness/ReplicaSetWithPrimary', __dirname); const rsWithoutPrimaryPath = f('%s/../spec/max-staleness/ReplicaSetNoPrimary', __dirname); diff --git a/test/core/functional/mongos_mocks/mixed_seed_list_tests.js b/test/core/functional/mongos_mocks/mixed_seed_list_tests.js index 87889e7227..ec37e0fb21 100644 --- a/test/core/functional/mongos_mocks/mixed_seed_list_tests.js +++ b/test/core/functional/mongos_mocks/mixed_seed_list_tests.js @@ -1,12 +1,17 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - mock = require('mongodb-mock-server'); +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); + +const core = require('../../../../lib/core'); +const Logger = core.Logger; +const Mongos = core.Mongos; +const ObjectId = core.BSON.ObjectId; describe('Mongos Mixed Seed List (mocks)', function() { afterEach(() => mock.cleanup()); - it('Should correctly print warning when non mongos proxy passed in seed list', { + it.skip('Should correctly print warning when non mongos proxy passed in seed list', { metadata: { requires: { generators: true, @@ -15,10 +20,6 @@ describe('Mongos Mixed Seed List (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos, - ObjectId = this.configuration.mongo.BSON.ObjectId, - Logger = this.configuration.mongo.Logger; - // Contain mock server var mongos1 = null; var mongos2 = null; @@ -72,22 +73,19 @@ describe('Mongos Mixed Seed List (mocks)', function() { size: 1 }); - var logger = Logger.currentLogger(); + const logger = Logger.currentLogger(); Logger.setCurrentLogger(function(msg, state) { expect(state.type).to.equal('warn'); expect(state.message).to.equal( - 'expected mongos proxy, but found replicaset member mongod for server localhost:52006' + `expected mongos proxy, but found replicaset member mongod for server ${mongos2.uri()}` ); - }); - // Add event listeners - server.once('connect', function() { Logger.setCurrentLogger(logger); - server.destroy(); done(); }); + // Add event listeners server.on('error', done); server.connect(); }); @@ -103,10 +101,6 @@ describe('Mongos Mixed Seed List (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos, - Logger = this.configuration.mongo.Logger, - ObjectId = this.configuration.mongo.BSON.ObjectId; - // Contain mock server var mongos1 = null; var mongos2 = null; diff --git a/test/core/functional/mongos_mocks/multiple_proxies_tests.js b/test/core/functional/mongos_mocks/multiple_proxies_tests.js index 2a658ba60f..49ffcf1533 100644 --- a/test/core/functional/mongos_mocks/multiple_proxies_tests.js +++ b/test/core/functional/mongos_mocks/multiple_proxies_tests.js @@ -1,7 +1,10 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - mock = require('mongodb-mock-server'); +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); + +const core = require('../../../../lib/core'); +const Mongos = core.Mongos; describe('Mongos Multiple Proxies (mocks)', function() { afterEach(() => mock.cleanup()); @@ -15,8 +18,6 @@ describe('Mongos Multiple Proxies (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos; - // Contain mock server var mongos1 = null; var mongos2 = null; @@ -106,8 +107,6 @@ describe('Mongos Multiple Proxies (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos; - // Default message fields var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { msg: 'isdbgrid' diff --git a/test/core/functional/mongos_mocks/proxy_failover_tests.js b/test/core/functional/mongos_mocks/proxy_failover_tests.js index cffb68352d..c9ec2421f5 100644 --- a/test/core/functional/mongos_mocks/proxy_failover_tests.js +++ b/test/core/functional/mongos_mocks/proxy_failover_tests.js @@ -1,7 +1,10 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - mock = require('mongodb-mock-server'); +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); + +const core = require('../../../../lib/core'); +const Mongos = core.Mongos; describe('Mongos Proxy Failover (mocks)', function() { afterEach(() => mock.cleanup()); @@ -15,8 +18,6 @@ describe('Mongos Proxy Failover (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos; - // Default message fields var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { msg: 'isdbgrid' @@ -88,8 +89,6 @@ describe('Mongos Proxy Failover (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos; - // Current index for the ismaster var currentStep = 0; @@ -185,8 +184,6 @@ describe('Mongos Proxy Failover (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos; - // Current index for the ismaster var currentStep = 0; diff --git a/test/core/functional/mongos_mocks/proxy_read_preference_tests.js b/test/core/functional/mongos_mocks/proxy_read_preference_tests.js index 55c2e5affe..9190d2c83d 100644 --- a/test/core/functional/mongos_mocks/proxy_read_preference_tests.js +++ b/test/core/functional/mongos_mocks/proxy_read_preference_tests.js @@ -1,7 +1,12 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - mock = require('mongodb-mock-server'); +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); + +const core = require('../../../../lib/core'); +const Mongos = core.Mongos; +const ReadPreference = core.ReadPreference; +const Long = core.BSON.Long; describe('Mongos Proxy Read Preference (mocks)', function() { afterEach(() => mock.cleanup()); @@ -15,10 +20,6 @@ describe('Mongos Proxy Read Preference (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos, - Long = this.configuration.mongo.BSON.Long, - ReadPreference = this.configuration.mongo.ReadPreference; - // Default message fields var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { msg: 'isdbgrid' @@ -99,10 +100,6 @@ describe('Mongos Proxy Read Preference (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos, - Long = this.configuration.mongo.BSON.Long, - ReadPreference = this.configuration.mongo.ReadPreference; - // Default message fields var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { msg: 'isdbgrid' @@ -183,9 +180,6 @@ describe('Mongos Proxy Read Preference (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos, - ReadPreference = this.configuration.mongo.ReadPreference; - // Default message fields var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { msg: 'isdbgrid' diff --git a/test/core/functional/mongos_mocks/single_proxy_connection_tests.js b/test/core/functional/mongos_mocks/single_proxy_connection_tests.js index faf81d0ad3..a14acd32dd 100644 --- a/test/core/functional/mongos_mocks/single_proxy_connection_tests.js +++ b/test/core/functional/mongos_mocks/single_proxy_connection_tests.js @@ -1,8 +1,13 @@ 'use strict'; -var expect = require('chai').expect, - f = require('util').format, - co = require('co'), - mock = require('mongodb-mock-server'); +const expect = require('chai').expect; +const f = require('util').format; +const co = require('co'); +const mock = require('mongodb-mock-server'); + +const core = require('../../../../lib/core'); +const Mongos = core.Mongos; +const ObjectId = core.BSON.ObjectId; +const Long = core.BSON.Long; describe('Mongos Single Proxy Connection (mocks)', function() { afterEach(() => mock.cleanup()); @@ -16,8 +21,6 @@ describe('Mongos Single Proxy Connection (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos; - // Current index for the ismaster var currentStep = 0; // Primary stop responding @@ -103,10 +106,6 @@ describe('Mongos Single Proxy Connection (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos, - Long = this.configuration.mongo.BSON.Long, - ObjectId = this.configuration.mongo.BSON.ObjectId; - // Default message fields var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { msg: 'isdbgrid' diff --git a/test/core/functional/mongos_server_selection_tests.js b/test/core/functional/mongos_server_selection_tests.js index fe33143c54..570b085782 100644 --- a/test/core/functional/mongos_server_selection_tests.js +++ b/test/core/functional/mongos_server_selection_tests.js @@ -3,9 +3,9 @@ const expect = require('chai').expect; const path = require('path'); const fs = require('fs'); -const Mongos = require('../../../lib/topologies/mongos'); -const ReadPreference = require('../../../lib/topologies/read_preference'); -const Server = require('../../../lib/topologies/server'); +const Mongos = require('../../../lib/core/topologies/mongos'); +const ReadPreference = require('../../../lib/core/topologies/read_preference'); +const Server = require('../../../lib/core/topologies/server'); describe('Mongos server selection tests', function() { var specPath = `${__dirname}/../spec/server-selection/server_selection/Sharded/read`; diff --git a/test/core/functional/operation_example_tests.js b/test/core/functional/operation_example_tests.js index 87c4cd2d23..db0cf39b74 100644 --- a/test/core/functional/operation_example_tests.js +++ b/test/core/functional/operation_example_tests.js @@ -1,6 +1,9 @@ 'use strict'; -var expect = require('chai').expect; +const expect = require('chai').expect; +const core = require('../../../lib/core'); +const ReplSet = core.ReplSet; +const Mongos = core.Mongos; /************************************************************************** * @@ -26,9 +29,7 @@ describe('Server operation example tests', function() { const config = this.configuration; // Attempt to connect - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { reconnect: true, reconnectInterval: 50 }); @@ -82,9 +83,7 @@ describe('Server operation example tests', function() { const config = this.configuration; // Attempt to connect - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { reconnect: true, reconnectInterval: 50 }); @@ -157,9 +156,7 @@ describe('Server operation example tests', function() { const config = this.configuration; // Attempt to connect - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { reconnect: true, reconnectInterval: 50 }); @@ -232,9 +229,7 @@ describe('Server operation example tests', function() { const config = this.configuration; // Attempt to connect - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { reconnect: true, reconnectInterval: 50 }); @@ -300,9 +295,7 @@ describe('Server operation example tests', function() { const config = this.configuration; // Attempt to connect - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { reconnect: true, reconnectInterval: 50 }); @@ -352,8 +345,6 @@ describe('Replset operation example tests', function() { }, test: function(done) { - var ReplSet = this.configuration.require.ReplSet; - var config = [ { host: this.configuration.host, @@ -414,8 +405,6 @@ describe('Replset operation example tests', function() { }, test: function(done) { - var ReplSet = this.configuration.require.ReplSet; - var config = [ { host: this.configuration.host, @@ -495,8 +484,6 @@ describe('Replset operation example tests', function() { }, test: function(done) { - var ReplSet = this.configuration.require.ReplSet; - var config = [ { host: this.configuration.host, @@ -576,8 +563,6 @@ describe('Replset operation example tests', function() { }, test: function(done) { - var ReplSet = this.configuration.require.ReplSet; - var config = [ { host: this.configuration.host, @@ -650,8 +635,6 @@ describe('Replset operation example tests', function() { }, test: function(done) { - var ReplSet = this.configuration.require.ReplSet; - var config = [ { host: this.configuration.host, @@ -711,8 +694,6 @@ describe.skip('Mongos operation example tests', function() { }, test: function(done) { - var Mongos = this.configuration.require.Mongos; - // Attempt to connect var server = new Mongos([ { @@ -761,8 +742,6 @@ describe.skip('Mongos operation example tests', function() { }, test: function(done) { - var Mongos = this.configuration.require.Mongos; - // Attempt to connect var server = new Mongos([ { @@ -830,8 +809,6 @@ describe.skip('Mongos operation example tests', function() { }, test: function(done) { - var Mongos = this.configuration.require.Mongos; - // Attempt to connect var server = new Mongos([ { @@ -899,8 +876,6 @@ describe.skip('Mongos operation example tests', function() { }, test: function(done) { - var Mongos = this.configuration.require.Mongos; - // Attempt to connect var server = new Mongos([ { @@ -961,8 +936,6 @@ describe.skip('Mongos operation example tests', function() { }, test: function(done) { - var Mongos = this.configuration.require.Mongos; - // Attempt to connect var server = new Mongos([ { diff --git a/test/core/functional/operations_tests.js b/test/core/functional/operations_tests.js index 5ac865e9ab..124f221a73 100644 --- a/test/core/functional/operations_tests.js +++ b/test/core/functional/operations_tests.js @@ -4,9 +4,12 @@ const expect = require('chai').expect; const f = require('util').format; const mock = require('mongodb-mock-server'); const ConnectionSpy = require('./shared').ConnectionSpy; -const Connection = require('../../../lib/connection/connection'); const setupDatabase = require('./shared').setupDatabase; +const core = require('../../../lib/core'); +const ReadPreference = core.ReadPreference; +const Connection = core.Connection; + const test = {}; describe('Operation tests', function() { beforeEach(function() { @@ -46,7 +49,6 @@ describe('Operation tests', function() { }, test: function(done) { - var ReadPreference = this.configuration.mongo.ReadPreference; const config = this.configuration; const server = config.newTopology(); diff --git a/test/core/functional/pool_tests.js b/test/core/functional/pool_tests.js index 4607c0ca34..cbc0df68f4 100644 --- a/test/core/functional/pool_tests.js +++ b/test/core/functional/pool_tests.js @@ -3,14 +3,14 @@ var expect = require('chai').expect, locateAuthMethod = require('./shared').locateAuthMethod, executeCommand = require('./shared').executeCommand, - Pool = require('../../../lib/connection/pool'), - Connection = require('../../../lib/connection/connection'), - Query = require('../../../lib/connection/commands').Query, + Pool = require('../../../lib/core/connection/pool'), + Connection = require('../../../lib/core/connection/connection'), + Query = require('../../../lib/core/connection/commands').Query, Bson = require('bson'), mock = require('mongodb-mock-server'), ConnectionSpy = require('./shared').ConnectionSpy; -const MongoCredentials = require('../../../lib/auth/mongo_credentials').MongoCredentials; +const MongoCredentials = require('../../../lib/core/auth/mongo_credentials').MongoCredentials; const test = {}; describe('Pool tests', function() { diff --git a/test/core/functional/replset_server_selection_tests.js b/test/core/functional/replset_server_selection_tests.js index 9a13782340..f756792a87 100644 --- a/test/core/functional/replset_server_selection_tests.js +++ b/test/core/functional/replset_server_selection_tests.js @@ -3,9 +3,9 @@ var expect = require('chai').expect, f = require('util').format, fs = require('fs'), - ReplSetState = require('../../../lib/topologies/replset_state'), - MongoError = require('../../../lib/error').MongoError, - ReadPreference = require('../../../lib/topologies/read_preference'); + 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() { @@ -86,10 +86,10 @@ function executeEntry(config, file, path) { replset.topologyType = topologyDescription.type; // For each server add them to the state topologyDescription.servers.forEach(function(s) { - var server = config.newTopology({ - host: s.address.split(':')[0], - port: parseInt(s.address.split(':')[1], 10) - }); + 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; diff --git a/test/core/functional/replset_state_tests.js b/test/core/functional/replset_state_tests.js index d8ad4cd429..71031573b2 100644 --- a/test/core/functional/replset_state_tests.js +++ b/test/core/functional/replset_state_tests.js @@ -4,7 +4,7 @@ const expect = require('chai').expect, f = require('util').format, fs = require('fs'), ObjectId = require('bson').ObjectId, - ReplSetState = require('../../../lib/topologies/replset_state'); + ReplSetState = require('../../../lib/core/topologies/replset_state'); describe('ReplicaSet state', function() { const path = f('%s/../spec/server-discovery-and-monitoring/rs', __dirname); diff --git a/test/core/functional/replset_tests.js b/test/core/functional/replset_tests.js index ab7ccfd120..0c5962065c 100644 --- a/test/core/functional/replset_tests.js +++ b/test/core/functional/replset_tests.js @@ -1,9 +1,13 @@ 'use strict'; -var expect = require('chai').expect, - f = require('util').format, - Connection = require('../../../lib/connection/connection'), - ReplSet = require('../../../lib/topologies/replset'); +const expect = require('chai').expect; +const f = require('util').format; + +const core = require('../../../lib/core'); +const Connection = core.Connection; +const Server = core.Server; +const ReplSet = core.ReplSet; +const ReadPreference = core.ReadPreference; var restartAndDone = function(configuration, done) { configuration.manager.restart(9, { waitMS: 2000 }).then(function() { @@ -481,9 +485,7 @@ describe.skip('A replica set', function() { test: function(done) { var self = this; - var Server = this.configuration.mongo.Server, - ReadPreference = this.configuration.require.ReadPreference, - manager = this.configuration.manager; + const manager = this.configuration.manager; // Get the primary server manager.primary().then(function(_manager) { diff --git a/test/core/functional/rs_mocks/add_remove_tests.js b/test/core/functional/rs_mocks/add_remove_tests.js index c02647c74c..3d627c020f 100644 --- a/test/core/functional/rs_mocks/add_remove_tests.js +++ b/test/core/functional/rs_mocks/add_remove_tests.js @@ -1,10 +1,14 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - Connection = require('../../../../lib/connection/connection'), - mock = require('mongodb-mock-server'), - ConnectionSpy = require('../shared').ConnectionSpy; +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); +const ConnectionSpy = require('../shared').ConnectionSpy; + +const core = require('../../../../lib/core'); +const Connection = core.Connection; +const ReplSet = core.ReplSet; +const ObjectId = core.BSON.ObjectId; let test = {}; describe('ReplSet Add Remove (mocks)', function() { @@ -29,9 +33,6 @@ describe('ReplSet Add Remove (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var currentIsMasterIndex = 0; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -200,9 +201,6 @@ describe('ReplSet Add Remove (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var currentIsMasterIndex = 0; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -395,9 +393,6 @@ describe('ReplSet Add Remove (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var currentIsMasterIndex = 0; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -634,9 +629,6 @@ describe('ReplSet Add Remove (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var currentIsMasterIndex = 0; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', diff --git a/test/core/functional/rs_mocks/all_servers_close_tests.js b/test/core/functional/rs_mocks/all_servers_close_tests.js index d593253a5a..55d13aa9ef 100644 --- a/test/core/functional/rs_mocks/all_servers_close_tests.js +++ b/test/core/functional/rs_mocks/all_servers_close_tests.js @@ -1,10 +1,14 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - Connection = require('../../../../lib/connection/connection'), - mock = require('mongodb-mock-server'), - ConnectionSpy = require('../shared').ConnectionSpy; +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); +const ConnectionSpy = require('../shared').ConnectionSpy; + +const core = require('../../../../lib/core'); +const Connection = core.Connection; +const ReplSet = core.ReplSet; +const ObjectId = core.BSON.ObjectId; let test = {}; describe('ReplSet All Servers Close (mocks)', function() { @@ -29,9 +33,6 @@ describe('ReplSet All Servers Close (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var die = false; @@ -173,9 +174,6 @@ describe('ReplSet All Servers Close (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var die = false; diff --git a/test/core/functional/rs_mocks/connection_tests.js b/test/core/functional/rs_mocks/connection_tests.js index 75b456f20b..3d2a6c86af 100644 --- a/test/core/functional/rs_mocks/connection_tests.js +++ b/test/core/functional/rs_mocks/connection_tests.js @@ -1,9 +1,13 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - Connection = require('../../../../lib/connection/connection'), - mock = require('mongodb-mock-server'), - ConnectionSpy = require('../shared').ConnectionSpy; +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); +const ConnectionSpy = require('../shared').ConnectionSpy; + +const core = require('../../../../lib/core'); +const Connection = core.Connection; +const ReplSet = core.ReplSet; +const ObjectId = core.BSON.ObjectId; let test = {}; describe('ReplSet Connection Tests (mocks)', function() { @@ -28,9 +32,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; // Default message fields @@ -156,9 +157,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -274,9 +272,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -385,9 +380,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -456,9 +448,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -561,9 +550,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -687,9 +673,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -797,9 +780,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -896,9 +876,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -1017,9 +994,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -1112,9 +1086,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -1226,9 +1197,6 @@ describe('ReplSet Connection Tests (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', diff --git a/test/core/functional/rs_mocks/failover_tests.js b/test/core/functional/rs_mocks/failover_tests.js index 2edeab12f6..dee39dfe2f 100644 --- a/test/core/functional/rs_mocks/failover_tests.js +++ b/test/core/functional/rs_mocks/failover_tests.js @@ -1,9 +1,14 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - Connection = require('../../../../lib/connection/connection'), - mock = require('mongodb-mock-server'), - ConnectionSpy = require('../shared').ConnectionSpy; +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); +const ConnectionSpy = require('../shared').ConnectionSpy; + +const core = require('../../../../lib/core'); +const Connection = core.Connection; +const Server = core.Server; +const ReplSet = core.ReplSet; +const ObjectId = core.BSON.ObjectId; let test = {}; describe('ReplSet Failover (mocks)', function() { @@ -28,10 +33,6 @@ describe('ReplSet Failover (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - Server = this.configuration.mongo.Server, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var currentIsMasterIndex = 0; var electionIds = [new ObjectId(0), new ObjectId(1)]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { @@ -239,10 +240,6 @@ describe('ReplSet Failover (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - Server = this.configuration.mongo.Server, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var currentIsMasterIndex = 0; var electionIds = [new ObjectId(0), new ObjectId(1)]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { diff --git a/test/core/functional/rs_mocks/maintanance_mode_tests.js b/test/core/functional/rs_mocks/maintanance_mode_tests.js index 6617dc0959..3d009c7808 100644 --- a/test/core/functional/rs_mocks/maintanance_mode_tests.js +++ b/test/core/functional/rs_mocks/maintanance_mode_tests.js @@ -1,9 +1,13 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - Connection = require('../../../../lib/connection/connection'), - mock = require('mongodb-mock-server'), - ConnectionSpy = require('../shared').ConnectionSpy; +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); +const ConnectionSpy = require('../shared').ConnectionSpy; + +const core = require('../../../../lib/core'); +const Connection = core.Connection; +const ReplSet = core.ReplSet; +const ObjectId = core.BSON.ObjectId; let test = {}; describe('ReplSet Maintenance Mode (mocks)', function() { @@ -28,9 +32,6 @@ describe('ReplSet Maintenance Mode (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var currentIsMasterIndex = 0; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', diff --git a/test/core/functional/rs_mocks/monitoring_tests.js b/test/core/functional/rs_mocks/monitoring_tests.js index 630300db75..030f12a9e2 100644 --- a/test/core/functional/rs_mocks/monitoring_tests.js +++ b/test/core/functional/rs_mocks/monitoring_tests.js @@ -1,9 +1,13 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - Connection = require('../../../../lib/connection/connection'), - mock = require('mongodb-mock-server'), - ConnectionSpy = require('../shared').ConnectionSpy; +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); +const ConnectionSpy = require('../shared').ConnectionSpy; + +const core = require('../../../../lib/core'); +const Connection = core.Connection; +const ReplSet = core.ReplSet; +const ObjectId = core.BSON.ObjectId; var delay = function(timeout) { return new Promise(resolve => setTimeout(() => resolve(), timeout)); @@ -34,9 +38,6 @@ describe('ReplSet Monitoring (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var currentIsMasterState = 0; var stopRespondingPrimary = false; @@ -236,9 +237,6 @@ describe('ReplSet Monitoring (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var electionIds = [new ObjectId(), new ObjectId()]; var currentIsMasterState = 0; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { diff --git a/test/core/functional/rs_mocks/no_primary_found_tests.js b/test/core/functional/rs_mocks/no_primary_found_tests.js index c698575173..b4e8ebe621 100644 --- a/test/core/functional/rs_mocks/no_primary_found_tests.js +++ b/test/core/functional/rs_mocks/no_primary_found_tests.js @@ -1,9 +1,13 @@ 'use strict'; const co = require('co'); -const Connection = require('../../../../lib/connection/connection'); const mock = require('mongodb-mock-server'); const ConnectionSpy = require('../shared').ConnectionSpy; +const core = require('../../../../lib/core'); +const Connection = core.Connection; +const ReplSet = core.ReplSet; +const ObjectId = core.BSON.ObjectId; + let test = {}; describe('ReplSet No Primary Found (mocks)', function() { beforeEach(() => { @@ -27,9 +31,6 @@ describe('ReplSet No Primary Found (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', setVersion: 1, diff --git a/test/core/functional/rs_mocks/operation_tests.js b/test/core/functional/rs_mocks/operation_tests.js index 92ee831f77..3e58437688 100644 --- a/test/core/functional/rs_mocks/operation_tests.js +++ b/test/core/functional/rs_mocks/operation_tests.js @@ -1,9 +1,14 @@ 'use strict'; const co = require('co'); -const Connection = require('../../../../lib/connection/connection'); const mock = require('mongodb-mock-server'); const ConnectionSpy = require('../shared').ConnectionSpy; +const core = require('../../../../lib/core'); +const Connection = core.Connection; +const ReplSet = core.ReplSet; +const ObjectId = core.BSON.ObjectId; +const ReadPreference = core.ReadPreference; + let test = {}; describe('ReplSet Operations (mocks)', function() { beforeEach(() => { @@ -27,9 +32,6 @@ describe('ReplSet Operations (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var currentIsMasterIndex = 0; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -98,10 +100,6 @@ describe('ReplSet Operations (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId, - ReadPreference = this.configuration.mongo.ReadPreference; - var currentIsMasterIndex = 0; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', diff --git a/test/core/functional/rs_mocks/primary_loses_network_tests.js b/test/core/functional/rs_mocks/primary_loses_network_tests.js index ce82fd0e83..dbdf090bee 100644 --- a/test/core/functional/rs_mocks/primary_loses_network_tests.js +++ b/test/core/functional/rs_mocks/primary_loses_network_tests.js @@ -1,9 +1,13 @@ 'use strict'; const co = require('co'); -const Connection = require('../../../../lib/connection/connection'); const mock = require('mongodb-mock-server'); const ConnectionSpy = require('../shared').ConnectionSpy; +const core = require('../../../../lib/core'); +const Connection = core.Connection; +const ReplSet = core.ReplSet; +const ObjectId = core.BSON.ObjectId; + let test = {}; describe('ReplSet Primary Loses Network (mocks)', function() { beforeEach(() => { @@ -27,9 +31,6 @@ describe('ReplSet Primary Loses Network (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - var currentIsMasterIndex = 0; var step = 0; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { diff --git a/test/core/functional/rs_mocks/read_preferences_tests.js b/test/core/functional/rs_mocks/read_preferences_tests.js index 67de87a51a..6f976c30f1 100644 --- a/test/core/functional/rs_mocks/read_preferences_tests.js +++ b/test/core/functional/rs_mocks/read_preferences_tests.js @@ -1,9 +1,16 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - Connection = require('../../../../lib/connection/connection'), - mock = require('mongodb-mock-server'), - ConnectionSpy = require('../shared').ConnectionSpy; +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); +const ConnectionSpy = require('../shared').ConnectionSpy; + +const core = require('../../../../lib/core'); +const Connection = core.Connection; +const MongoError = core.MongoError; +const ReplSet = core.ReplSet; +const ObjectId = core.BSON.ObjectId; +const ReadPreference = core.ReadPreference; +const Long = core.BSON.Long; let test = {}; describe('ReplSet Read Preferences (mocks)', function() { @@ -28,11 +35,6 @@ describe('ReplSet Read Preferences (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId, - ReadPreference = this.configuration.mongo.ReadPreference, - Long = this.configuration.mongo.BSON.Long; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -168,11 +170,6 @@ describe('ReplSet Read Preferences (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId, - ReadPreference = this.configuration.mongo.ReadPreference, - Long = this.configuration.mongo.BSON.Long; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -307,11 +304,6 @@ describe('ReplSet Read Preferences (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId, - ReadPreference = this.configuration.mongo.ReadPreference, - Long = this.configuration.mongo.BSON.Long; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -480,12 +472,6 @@ describe('ReplSet Read Preferences (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId, - ReadPreference = this.configuration.mongo.ReadPreference, - Long = this.configuration.mongo.BSON.Long, - MongoError = this.configuration.mongo.MongoError; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -638,11 +624,6 @@ describe('ReplSet Read Preferences (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId, - ReadPreference = this.configuration.mongo.ReadPreference, - Long = this.configuration.mongo.BSON.Long; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -813,11 +794,6 @@ describe('ReplSet Read Preferences (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId, - ReadPreference = this.configuration.mongo.ReadPreference, - Long = this.configuration.mongo.BSON.Long; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -958,11 +934,6 @@ describe('ReplSet Read Preferences (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId, - ReadPreference = this.configuration.mongo.ReadPreference, - Long = this.configuration.mongo.BSON.Long; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -1106,11 +1077,6 @@ describe('ReplSet Read Preferences (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId, - ReadPreference = this.configuration.mongo.ReadPreference, - Long = this.configuration.mongo.BSON.Long; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', @@ -1197,11 +1163,6 @@ describe('ReplSet Read Preferences (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId, - ReadPreference = this.configuration.mongo.ReadPreference, - Long = this.configuration.mongo.BSON.Long; - var electionIds = [new ObjectId(), new ObjectId()]; var defaultFields = Object.assign({}, mock.DEFAULT_ISMASTER, { setName: 'rs', diff --git a/test/core/functional/sdam_monitoring_mocks/mongos_topology_tests.js b/test/core/functional/sdam_monitoring_mocks/mongos_topology_tests.js index eb30dfc445..654aa4b0dd 100644 --- a/test/core/functional/sdam_monitoring_mocks/mongos_topology_tests.js +++ b/test/core/functional/sdam_monitoring_mocks/mongos_topology_tests.js @@ -1,7 +1,10 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - mock = require('mongodb-mock-server'); +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); + +const core = require('../../../../lib/core'); +const Mongos = core.Mongos; describe.skip('Mongos SDAM Monitoring (mocks)', function() { it('SDAM Monitoring Should correctly connect to two proxies', { @@ -13,8 +16,6 @@ describe.skip('Mongos SDAM Monitoring (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos; - // Contain mock server var mongos1 = null; var mongos2 = null; @@ -216,8 +217,6 @@ describe.skip('Mongos SDAM Monitoring (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos; - // Contain mock server var mongos1 = null; var mongos2 = null; @@ -406,8 +405,6 @@ describe.skip('Mongos SDAM Monitoring (mocks)', function() { }, test: function(done) { - var Mongos = this.configuration.mongo.Mongos; - // Contain mock server var mongos1 = null; var mongos2 = null; diff --git a/test/core/functional/sdam_monitoring_mocks/replset_topology_tests.js b/test/core/functional/sdam_monitoring_mocks/replset_topology_tests.js index 65a1a2b267..56d14622aa 100644 --- a/test/core/functional/sdam_monitoring_mocks/replset_topology_tests.js +++ b/test/core/functional/sdam_monitoring_mocks/replset_topology_tests.js @@ -1,7 +1,11 @@ 'use strict'; -var expect = require('chai').expect, - co = require('co'), - mock = require('mongodb-mock-server'); +const expect = require('chai').expect; +const co = require('co'); +const mock = require('mongodb-mock-server'); + +const core = require('../../../../lib/core'); +const ReplSet = core.ReplSet; +const ObjectId = core.BSON.ObjectId; describe.skip('ReplSet SDAM Monitoring (mocks)', function() { afterEach(() => mock.cleanup()); @@ -15,9 +19,6 @@ describe.skip('ReplSet SDAM Monitoring (mocks)', function() { }, test: function(done) { - var ReplSet = this.configuration.mongo.ReplSet, - ObjectId = this.configuration.mongo.BSON.ObjectId; - // Contain mock server var primaryServer = null; var firstSecondaryServer = null; diff --git a/test/core/functional/sdam_monitoring_mocks/single_topology_tests.js b/test/core/functional/sdam_monitoring_mocks/single_topology_tests.js index bdccef47e9..dd6e639353 100644 --- a/test/core/functional/sdam_monitoring_mocks/single_topology_tests.js +++ b/test/core/functional/sdam_monitoring_mocks/single_topology_tests.js @@ -40,13 +40,11 @@ describe.skip('Single SDAM Monitoring (mocks)', function() { }); // Attempt to connect - server = config.newTopology( - Object.assign({}, mockServer.address(), { - connectionTimeout: 3000, - socketTimeout: 1000, - size: 1 - }) - ); + server = config.newTopology(mockServer.address().host, mockServer.address().port, { + connectionTimeout: 3000, + socketTimeout: 1000, + size: 1 + }); // Results var flags = []; @@ -179,13 +177,11 @@ describe.skip('Single SDAM Monitoring (mocks)', function() { }); // Attempt to connect - server = config.newTopology( - Object.assign({}, mockServer.address(), { - connectionTimeout: 3000, - socketTimeout: 1000, - size: 1 - }) - ); + server = config.newTopology(mockServer.address().host, mockServer.address().port, { + connectionTimeout: 3000, + socketTimeout: 1000, + size: 1 + }); // Results var flags = []; diff --git a/test/core/functional/server_tests.js b/test/core/functional/server_tests.js index 9776e19c10..84fbfdba2d 100644 --- a/test/core/functional/server_tests.js +++ b/test/core/functional/server_tests.js @@ -4,10 +4,13 @@ const f = require('util').format; const locateAuthMethod = require('./shared').locateAuthMethod; const executeCommand = require('./shared').executeCommand; const Bson = require('bson'); -const Connection = require('../../../lib/connection/connection'); const mock = require('mongodb-mock-server'); const Buffer = require('safe-buffer').Buffer; -const MongoCredentials = require('../../../lib/auth/mongo_credentials').MongoCredentials; + +const core = require('../../../lib/core'); +const ReadPreference = core.ReadPreference; +const MongoCredentials = core.MongoCredentials; +const Connection = core.Connection; describe('Server tests', function() { it('should correctly connect server to single instance', { @@ -15,9 +18,7 @@ describe('Server tests', function() { test: function(done) { const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson() }); @@ -37,9 +38,7 @@ describe('Server tests', function() { test: function(done) { const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson() }); @@ -65,9 +64,7 @@ describe('Server tests', function() { test: function(done) { const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson() }); @@ -100,9 +97,7 @@ describe('Server tests', function() { test: function(done) { const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson() }); @@ -136,12 +131,8 @@ describe('Server tests', function() { metadata: { requires: { topology: 'single' } }, test: function(done) { - var ReadPreference = this.configuration.mongo.ReadPreference; - const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson(), compression: { compressors: ['snappy', 'zlib'] } }); @@ -176,9 +167,7 @@ describe('Server tests', function() { test: function(done) { const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson() }); @@ -216,9 +205,7 @@ describe('Server tests', function() { test: function(done) { const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson() }); @@ -256,9 +243,7 @@ describe('Server tests', function() { test: function(done) { const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson() }); @@ -297,9 +282,7 @@ describe('Server tests', function() { test: function(done) { const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson() }); @@ -344,9 +327,7 @@ describe('Server tests', function() { var testDone = false; const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson() }); @@ -431,11 +412,8 @@ describe('Server tests', function() { }, test: function(done) { - var ReadPreference = this.configuration.mongo.ReadPreference; const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { reconnect: true, size: 1, reconnectInterval: 50 @@ -512,10 +490,7 @@ describe('Server tests', function() { return this.skip(); } - var ReadPreference = this.configuration.require.ReadPreference; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { reconnect: false, size: 1 }); @@ -585,9 +560,7 @@ describe('Server tests', function() { manager.stop('SIGINT').then(function() { // Attempt to connect while server is down - var server = config.newTopology({ - host: self.configuration.host, - port: self.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { reconnect: true, reconnectTries: 2, size: 1, @@ -624,12 +597,8 @@ describe('Server tests', function() { }, test: function(done) { - var ReadPreference = this.configuration.require.ReadPreference; - const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { reconnect: true, size: 1, reconnectInterval: 50 @@ -697,9 +666,7 @@ describe('Server tests', function() { test: function(done) { var self = this; const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { reconnect: true, reconnectTries: 2, size: 50, @@ -751,9 +718,7 @@ describe('Server tests', function() { // The actual test we wish to run test: function(done) { const config = this.configuration; - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { size: 10, bson: new Bson() }); @@ -823,9 +788,7 @@ describe('Server tests', function() { const config = this.configuration; try { - config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, + config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson(), compression: { compressors: ['notACompressor', 'alsoNotACompressor', 'snappy'] } }); @@ -873,9 +836,7 @@ describe('Server tests', function() { expect(cmdErr).to.not.exist; expect(r).to.exist; - var server = config.newTopology({ - host: self.configuration.host, - port: self.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson(), compression: { compressors: ['snappy', 'zlib'] } }); @@ -951,9 +912,7 @@ describe('Server tests', function() { expect(cmdErr).to.not.exist; expect(r).to.exist; - var server = config.newTopology({ - host: self.configuration.host, - port: self.configuration.port, + var server = config.newTopology(this.configuration.host, this.configuration.port, { bson: new Bson(), compression: { compressors: ['snappy', 'zlib'] } }); @@ -986,10 +945,8 @@ describe('Server tests', function() { return this.skip(); } - var server = config.newTopology({ - host: this.configuration.host, - port: this.configuration.port, - bson: new Bson(), + var server = config.newTopology(this.configuration.host, this.configuration.port, { + bson: new sBson(), compression: { compressors: ['snappy', 'zlib'] } @@ -1039,7 +996,7 @@ describe('Server tests', function() { }); const config = this.configuration; - var client = config.newTopology(server.address()); + var client = config.newTopology(server.address().host, server.address().port); client.on('error', error => { let err; try { @@ -1066,8 +1023,7 @@ describe('Server tests', function() { test: function(done) { const config = this.configuration; - var server = config.newTopology({ - host: 'doesntexist', + var server = config.newTopology('doesntexist', 12345, { bson: new Bson(), reconnectTries: 0 }); diff --git a/test/core/functional/shared.js b/test/core/functional/shared.js index 3e9179ed29..e8c0a53f1b 100644 --- a/test/core/functional/shared.js +++ b/test/core/functional/shared.js @@ -1,10 +1,10 @@ 'use strict'; const EventEmitter = require('events'); -const Pool = require('../../../lib/connection/pool'); +const Pool = require('../../../lib/core/connection/pool'); const f = require('util').format; const bson = require('bson'); -const Query = require('../../../lib/connection/commands').Query; -const ReadPreference = require('../../../lib/topologies/read_preference'); +const Query = require('../../../lib/core/connection/commands').Query; +const ReadPreference = require('../../../lib/core/topologies/read_preference'); function executeCommand(configuration, db, cmd, options, cb) { // Optional options @@ -51,10 +51,10 @@ function executeCommand(configuration, db, cmd, options, cb) { } function locateAuthMethod(configuration, cb) { - var Pool = require('../../../lib/connection/pool'), + var Pool = require('../../../lib/core/connection/pool'), bson = require('bson'), f = require('util').format, - Query = require('../../../lib/connection/commands').Query; + Query = require('../../../lib/core/connection/commands').Query; // Set up operations var db = 'admin'; diff --git a/test/core/functional/single_mocks/compression_tests.js b/test/core/functional/single_mocks/compression_tests.js index 9664db676c..513d008b6a 100644 --- a/test/core/functional/single_mocks/compression_tests.js +++ b/test/core/functional/single_mocks/compression_tests.js @@ -28,14 +28,12 @@ describe('Single Compression (mocks)', function() { request.reply(serverResponse); }); - const client = config.newTopology( - Object.assign({}, server.address(), { - connectionTimeout: 5000, - socketTimeout: 1000, - size: 1, - compression: { compressors: ['snappy', 'zlib'], zlibCompressionLevel: -1 } - }) - ); + const client = config.newTopology(server.address().host, server.address().port, { + connectionTimeout: 5000, + socketTimeout: 1000, + size: 1, + compression: { compressors: ['snappy', 'zlib'], zlibCompressionLevel: -1 } + }); client.on('connect', function() { client.destroy(); @@ -94,14 +92,12 @@ describe('Single Compression (mocks)', function() { }); // Attempt to connect - var client = config.newTopology( - Object.assign({}, server.address(), { - connectionTimeout: 5000, - socketTimeout: 1000, - size: 1, - compression: { compressors: ['snappy', 'zlib'] } - }) - ); + var client = config.newTopology(server.address().host, server.address().port, { + connectionTimeout: 5000, + socketTimeout: 1000, + size: 1, + compression: { compressors: ['snappy', 'zlib'] } + }); // Connect and try inserting, updating, and removing // All outbound messages from the driver will be uncompressed @@ -188,14 +184,12 @@ describe('Single Compression (mocks)', function() { currentStep++; }); - var client = config.newTopology( - Object.assign({}, server.address(), { - connectionTimeout: 5000, - socketTimeout: 1000, - size: 1, - compression: { compressors: ['snappy', 'zlib'] } - }) - ); + var client = config.newTopology(server.address().host, server.address().port, { + connectionTimeout: 5000, + socketTimeout: 1000, + size: 1, + compression: { compressors: ['snappy', 'zlib'] } + }); // Connect and try inserting, updating, and removing // All outbound messages from the driver (after initial connection) will be OP_COMPRESSED using snappy @@ -284,14 +278,12 @@ describe('Single Compression (mocks)', function() { }); // Attempt to connect - var client = config.newTopology( - Object.assign({}, server.address(), { - connectionTimeout: 5000, - socketTimeout: 1000, - size: 1, - compression: { compressors: ['snappy', 'zlib'] } - }) - ); + var client = config.newTopology(server.address().host, server.address().port, { + connectionTimeout: 5000, + socketTimeout: 1000, + size: 1, + compression: { compressors: ['snappy', 'zlib'] } + }); // Connect and try inserting, updating, and removing // All outbound messages from the driver (after initial connection) will be OP_COMPRESSED using zlib @@ -370,14 +362,12 @@ describe('Single Compression (mocks)', function() { currentStep++; }); - var client = config.newTopology( - Object.assign({}, server.address(), { - connectionTimeout: 5000, - socketTimeout: 1000, - size: 1, - compression: { compressors: ['snappy', 'zlib'] } - }) - ); + var client = config.newTopology(server.address().host, server.address().port, { + connectionTimeout: 5000, + socketTimeout: 1000, + size: 1, + compression: { compressors: ['snappy', 'zlib'] } + }); // Connect and try some commands, checking that uncompressible commands are indeed not compressed client.on('connect', function(_server) { diff --git a/test/core/functional/single_mocks/timeout_tests.js b/test/core/functional/single_mocks/timeout_tests.js index e7b01144a3..ba8c72623d 100644 --- a/test/core/functional/single_mocks/timeout_tests.js +++ b/test/core/functional/single_mocks/timeout_tests.js @@ -65,13 +65,11 @@ describe('Single Timeout (mocks)', function() { stopRespondingPrimary = true; }, 5000); - var replset = config.newTopology( - Object.assign({}, server.address(), { - connectionTimeout: 5000, - socketTimeout: 1000, - size: 1 - }) - ); + var replset = config.newTopology(server.address().host, server.address().port, { + connectionTimeout: 5000, + socketTimeout: 1000, + size: 1 + }); // Not done var finished = false; @@ -159,13 +157,11 @@ describe('Single Timeout (mocks)', function() { } }); - var server = config.newTopology( - Object.assign({}, mockServer.address(), { - connectionTimeout: 3000, - socketTimeout: 2000, - size: 1 - }) - ); + var server = config.newTopology(server.address().host, server.address().port, { + connectionTimeout: 3000, + socketTimeout: 2000, + size: 1 + }); var docs = []; // Create big insert message @@ -299,13 +295,11 @@ describe('Single Timeout (mocks)', function() { } }); - var server = config.newTopology( - Object.assign({}, mockServer.address(), { - connectionTimeout: 2000, - socketTimeout: 1000, - size: 1 - }) - ); + var server = config.newTopology(mockServer.address().host, mockServer.address().port, { + connectionTimeout: 2000, + socketTimeout: 1000, + size: 1 + }); // Add event listeners server.once('connect', function() { diff --git a/test/core/functional/srv_polling_tests.js b/test/core/functional/srv_polling_tests.js index 716954d5d9..484aff1c01 100644 --- a/test/core/functional/srv_polling_tests.js +++ b/test/core/functional/srv_polling_tests.js @@ -1,12 +1,12 @@ 'use strict'; -const Topology = require('../../../lib/sdam/topology'); -const _topologyDescription = require('../../../lib/sdam/topology_description'); +const Topology = require('../../../lib/core/sdam/topology'); +const _topologyDescription = require('../../../lib/core/sdam/topology_description'); const TopologyDescription = _topologyDescription.TopologyDescription; const TopologyType = _topologyDescription.TopologyType; -const monitoring = require('../../../lib/sdam/monitoring'); -const SrvPoller = require('../../../lib/sdam/srv_polling').SrvPoller; -const SrvPollingEvent = require('../../../lib/sdam/srv_polling').SrvPollingEvent; +const monitoring = require('../../../lib/core/sdam/monitoring'); +const SrvPoller = require('../../../lib/core/sdam/srv_polling').SrvPoller; +const SrvPollingEvent = require('../../../lib/core/sdam/srv_polling').SrvPollingEvent; const dns = require('dns'); const EventEmitter = require('events').EventEmitter; diff --git a/test/core/unit/apm_tests.js b/test/core/unit/apm_tests.js index 8a9e59d4bb..56fade72e8 100644 --- a/test/core/unit/apm_tests.js +++ b/test/core/unit/apm_tests.js @@ -1,11 +1,11 @@ 'use strict'; -const Pool = require('../../../lib/connection/pool'); +const Pool = require('../../../lib/core/connection/pool'); const BSON = require('bson'); -const apm = require('../../../lib/connection/apm'); +const apm = require('../../../lib/core/connection/apm'); const expect = require('chai').expect; -const commands = require('../../../lib/connection/commands'); +const commands = require('../../../lib/core/connection/commands'); const Query = commands.Query; const KillCursor = commands.KillCursor; const GetMore = commands.GetMore; diff --git a/test/core/unit/common.js b/test/core/unit/common.js index 9764543cf7..afa956d5b3 100644 --- a/test/core/unit/common.js +++ b/test/core/unit/common.js @@ -123,8 +123,30 @@ function genClusterTime(time) { }; } +function sessionCleanupHandler(session, sessionPool, done) { + return err => { + if (session == null) { + sessionPool.endAllPooledSessions(); + done(); + return; + } + + if (session.hasEnded) { + sessionPool.endAllPooledSessions(); + done(err); + return; + } + + session.endSession(() => { + sessionPool.endAllPooledSessions(); + done(err); + }); + }; +} + module.exports = { ReplSetFixture: ReplSetFixture, MongosFixture: MongosFixture, - genClusterTime: genClusterTime + genClusterTime: genClusterTime, + sessionCleanupHandler }; diff --git a/test/core/unit/connect_tests.js b/test/core/unit/connect_tests.js index cd511d946d..7d4e8c6a8d 100644 --- a/test/core/unit/connect_tests.js +++ b/test/core/unit/connect_tests.js @@ -4,10 +4,10 @@ const BSON = require('bson'); const mock = require('mongodb-mock-server'); const expect = require('chai').expect; -const connect = require('../../../lib/connection/connect'); -const MongoCredentials = require('../../../lib/auth/mongo_credentials').MongoCredentials; +const connect = require('../../../lib/core/connection/connect'); +const MongoCredentials = require('../../../lib/core/auth/mongo_credentials').MongoCredentials; const genClusterTime = require('./common').genClusterTime; -const MongoNetworkError = require('../../../lib/error').MongoNetworkError; +const MongoNetworkError = require('../../../lib/core/error').MongoNetworkError; describe('Connect Tests', function() { const test = {}; diff --git a/test/core/unit/connection_string_tests.js b/test/core/unit/connection_string_tests.js index b3e2940bdf..d46c4b5d07 100644 --- a/test/core/unit/connection_string_tests.js +++ b/test/core/unit/connection_string_tests.js @@ -1,9 +1,9 @@ 'use strict'; -const parseConnectionString = require('../../../lib/uri_parser'); +const parseConnectionString = require('../../../lib/core/uri_parser'); const fs = require('fs'); const punycode = require('punycode'); -const MongoParseError = require('../../../lib/error').MongoParseError; +const MongoParseError = require('../../../lib/core/error').MongoParseError; const chai = require('chai'); const expect = chai.expect; chai.use(require('chai-subset')); diff --git a/test/core/unit/mongodb_srv_tests.js b/test/core/unit/mongodb_srv_tests.js index 48363a8627..30e3b01fdb 100644 --- a/test/core/unit/mongodb_srv_tests.js +++ b/test/core/unit/mongodb_srv_tests.js @@ -1,7 +1,7 @@ 'use strict'; const fs = require('fs'); const path = require('path'); -const parseConnectionString = require('../../../lib/uri_parser'); +const parseConnectionString = require('../../../lib/core/uri_parser'); const expect = require('chai').expect; describe('mongodb+srv', function() { diff --git a/test/core/unit/mongos/events_tests.js b/test/core/unit/mongos/events_tests.js index aabe2f3cae..65764818ce 100644 --- a/test/core/unit/mongos/events_tests.js +++ b/test/core/unit/mongos/events_tests.js @@ -1,7 +1,7 @@ 'use strict'; const expect = require('chai').expect; -const Mongos = require('../../../../lib/topologies/mongos'); +const Mongos = require('../../../../lib/core/topologies/mongos'); const mock = require('mongodb-mock-server'); const MongosFixture = require('../common').MongosFixture; diff --git a/test/core/unit/mongos/reconnect_tests.js b/test/core/unit/mongos/reconnect_tests.js index 3de71ceaee..5fb50c0adb 100644 --- a/test/core/unit/mongos/reconnect_tests.js +++ b/test/core/unit/mongos/reconnect_tests.js @@ -1,11 +1,11 @@ 'use strict'; -const Mongos = require('../../../../lib/topologies/mongos'); +const Mongos = require('../../../../lib/core/topologies/mongos'); const expect = require('chai').expect; const mock = require('mongodb-mock-server'); const genClusterTime = require('../common').genClusterTime; -const Connection = require('../../../../lib/connection/connection'); +const Connection = require('../../../../lib/core/connection/connection'); const ConnectionSpy = require('../../functional/shared').ConnectionSpy; describe.skip('Reconnect (Mongos)', function() { diff --git a/test/core/unit/mongos/retryable_writes_tests.js b/test/core/unit/mongos/retryable_writes_tests.js index 9d0fe52a26..7d040ab5e9 100644 --- a/test/core/unit/mongos/retryable_writes_tests.js +++ b/test/core/unit/mongos/retryable_writes_tests.js @@ -1,10 +1,13 @@ 'use strict'; -var expect = require('chai').expect, - Mongos = require('../../../../lib/topologies/mongos'), - mock = require('mongodb-mock-server'), - MongosFixture = require('../common').MongosFixture, - ClientSession = require('../../../../lib/sessions').ClientSession, - ServerSessionPool = require('../../../../lib/sessions').ServerSessionPool; +const expect = require('chai').expect; +const mock = require('mongodb-mock-server'); +const MongosFixture = require('../common').MongosFixture; +const sessionCleanupHandler = require('../common').sessionCleanupHandler; + +const core = require('../../../../lib/core'); +const ClientSession = core.Sessions.ClientSession; +const ServerSessionPool = core.Sessions.ServerSessionPool; +const Mongos = core.Mongos; const test = new MongosFixture(); describe('Retryable Writes (Mongos)', function() { @@ -24,6 +27,7 @@ describe('Retryable Writes (Mongos)', function() { const sessionPool = new ServerSessionPool(topology); const session = new ClientSession(topology, sessionPool); + done = sessionCleanupHandler(session, sessionPool, done); let command = null; const messageHandler = () => { @@ -72,6 +76,7 @@ describe('Retryable Writes (Mongos)', function() { const sessionPool = new ServerSessionPool(mongos); const session = new ClientSession(mongos, sessionPool); + done = sessionCleanupHandler(session, sessionPool, done); let command = null, insertCount = 0; @@ -103,8 +108,6 @@ describe('Retryable Writes (Mongos)', function() { expect(err).to.not.exist; expect(command).to.have.property('txnNumber'); expect(command.txnNumber).to.eql(1); - - mongos.destroy(); done(); }); }); @@ -127,6 +130,7 @@ describe('Retryable Writes (Mongos)', function() { const sessionPool = new ServerSessionPool(mongos); const session = new ClientSession(mongos, sessionPool); + done = sessionCleanupHandler(session, sessionPool, done); let command = null, insertCount = 0; @@ -158,8 +162,10 @@ describe('Retryable Writes (Mongos)', function() { expect(command).to.have.property('txnNumber'); expect(command.txnNumber).to.eql(1); - mongos.destroy(); - done(); + session.endSession(() => { + mongos.destroy(); + done(); + }); }); }); diff --git a/test/core/unit/mongos/sessions_tests.js b/test/core/unit/mongos/sessions_tests.js index 7e72b1dd7b..bd33651423 100644 --- a/test/core/unit/mongos/sessions_tests.js +++ b/test/core/unit/mongos/sessions_tests.js @@ -1,13 +1,14 @@ 'use strict'; -var Mongos = require('../../../../lib/topologies/mongos'), - expect = require('chai').expect, - mock = require('mongodb-mock-server'), - genClusterTime = require('../common').genClusterTime; +const expect = require('chai').expect; +const mock = require('mongodb-mock-server'); +const genClusterTime = require('../common').genClusterTime; +const sessionCleanupHandler = require('../common').sessionCleanupHandler; -const sessions = require('../../../../lib/sessions'); -const ServerSessionPool = sessions.ServerSessionPool; -const ClientSession = sessions.ClientSession; -const ReadPreference = require('../../../../lib/topologies/read_preference'); +const core = require('../../../../lib/core'); +const ServerSessionPool = core.Sessions.ServerSessionPool; +const ClientSession = core.Sessions.ClientSession; +const ReadPreference = core.ReadPreference; +const Mongos = core.Mongos; const test = {}; describe('Sessions (Mongos)', function() { @@ -213,6 +214,8 @@ describe('Sessions (Mongos)', function() { }; const pool = new ServerSessionPool(mongos); const session = new ClientSession(mongos, pool); + done = sessionCleanupHandler(session, pool, done); + const readPreference = new ReadPreference('primaryPreferred'); const cursor = mongos.cursor('testdb.testcollection', findCommand, { diff --git a/test/core/unit/pool_tests.js b/test/core/unit/pool_tests.js index 5ff8171ede..81fa43fa2a 100644 --- a/test/core/unit/pool_tests.js +++ b/test/core/unit/pool_tests.js @@ -2,8 +2,8 @@ const expect = require('chai').expect; const mock = require('mongodb-mock-server'); -const Server = require('../../../lib/topologies/server'); -const MongoWriteConcernError = require('../../../lib/error').MongoWriteConcernError; +const Server = require('../../../lib/core/topologies/server'); +const MongoWriteConcernError = require('../../../lib/core/error').MongoWriteConcernError; const sinon = require('sinon'); const test = {}; @@ -42,6 +42,7 @@ describe('Pool (unit)', function() { expect(err).to.exist; expect(result).to.not.exist; expect(err).to.be.instanceOf(MongoWriteConcernError); + client.destroy(); done(); }); }); @@ -71,6 +72,7 @@ describe('Pool (unit)', function() { expect(query.slaveOk).to.be.false; client.s.pool.write.restore(); + client.destroy(); done(); }); }); diff --git a/test/core/unit/replset/auth_tests.js b/test/core/unit/replset/auth_tests.js index 16566ed52b..6c46fb5e5e 100644 --- a/test/core/unit/replset/auth_tests.js +++ b/test/core/unit/replset/auth_tests.js @@ -1,10 +1,10 @@ 'use strict'; -const ReplSet = require('../../../../lib/topologies/replset'); +const ReplSet = require('../../../../lib/core/topologies/replset'); const mock = require('mongodb-mock-server'); const ReplSetFixture = require('../common').ReplSetFixture; -const ReadPreference = require('../../../../lib/topologies/read_preference'); -const MongoCredentials = require('../../../../lib/auth/mongo_credentials').MongoCredentials; +const ReadPreference = require('../../../../lib/core/topologies/read_preference'); +const MongoCredentials = require('../../../../lib/core/auth/mongo_credentials').MongoCredentials; describe('Auth (ReplSet)', function() { let test; diff --git a/test/core/unit/replset/compression_tests.js b/test/core/unit/replset/compression_tests.js index 81918d4891..042aba141b 100644 --- a/test/core/unit/replset/compression_tests.js +++ b/test/core/unit/replset/compression_tests.js @@ -1,6 +1,6 @@ 'use strict'; -const ReplSet = require('../../../../lib/topologies/replset'); +const ReplSet = require('../../../../lib/core/topologies/replset'); const mock = require('mongodb-mock-server'); const ReplSetFixture = require('../common').ReplSetFixture; const expect = require('chai').expect; diff --git a/test/core/unit/replset/read_preference_tests.js b/test/core/unit/replset/read_preference_tests.js index d0b46be36c..42164bfc34 100644 --- a/test/core/unit/replset/read_preference_tests.js +++ b/test/core/unit/replset/read_preference_tests.js @@ -1,11 +1,11 @@ 'use strict'; const expect = require('chai').expect; -const ReplSet = require('../../../../lib/topologies/replset'); -const ReadPreference = require('../../../../lib/topologies/read_preference'); +const ReplSet = require('../../../../lib/core/topologies/replset'); +const ReadPreference = require('../../../../lib/core/topologies/read_preference'); const mock = require('mongodb-mock-server'); const ReplSetFixture = require('../common').ReplSetFixture; -const ReplSetState = require('../../../../lib/topologies/replset_state'); +const ReplSetState = require('../../../../lib/core/topologies/replset_state'); const MongoError = require('../../../..').MongoError; describe('ReadPreference (ReplSet)', function() { diff --git a/test/core/unit/replset/retryable_writes_tests.js b/test/core/unit/replset/retryable_writes_tests.js index 09774822a7..947e10bcc6 100644 --- a/test/core/unit/replset/retryable_writes_tests.js +++ b/test/core/unit/replset/retryable_writes_tests.js @@ -1,10 +1,13 @@ 'use strict'; -var expect = require('chai').expect, - ReplSet = require('../../../../lib/topologies/replset'), - mock = require('mongodb-mock-server'), - ReplSetFixture = require('../common').ReplSetFixture, - ClientSession = require('../../../../lib/sessions').ClientSession, - ServerSessionPool = require('../../../../lib/sessions').ServerSessionPool; +const expect = require('chai').expect; +const mock = require('mongodb-mock-server'); +const ReplSetFixture = require('../common').ReplSetFixture; +const sessionCleanupHandler = require('../common').sessionCleanupHandler; + +const core = require('../../../../lib/core'); +const ClientSession = core.Sessions.ClientSession; +const ServerSessionPool = core.Sessions.ServerSessionPool; +const ReplSet = core.ReplSet; const test = new ReplSetFixture(); describe('Retryable Writes (ReplSet)', function() { @@ -27,6 +30,7 @@ describe('Retryable Writes (ReplSet)', function() { const sessionPool = new ServerSessionPool(replset); const session = new ClientSession(replset, sessionPool); + done = sessionCleanupHandler(session, sessionPool, done); let command = null; test.primaryServer.setMessageHandler(request => { @@ -74,6 +78,7 @@ describe('Retryable Writes (ReplSet)', function() { const sessionPool = new ServerSessionPool(replset); const session = new ClientSession(replset, sessionPool); + done = sessionCleanupHandler(session, sessionPool, done); let command = null, insertCount = 0; @@ -129,6 +134,7 @@ describe('Retryable Writes (ReplSet)', function() { const sessionPool = new ServerSessionPool(replset); const session = new ClientSession(replset, sessionPool); + done = sessionCleanupHandler(session, sessionPool, done); let command = null, insertCount = 0; diff --git a/test/core/unit/replset/sessions_tests.js b/test/core/unit/replset/sessions_tests.js index 773f2b1e0d..d2bbd67bb3 100644 --- a/test/core/unit/replset/sessions_tests.js +++ b/test/core/unit/replset/sessions_tests.js @@ -1,6 +1,6 @@ 'use strict'; var expect = require('chai').expect, - ReplSet = require('../../../../lib/topologies/replset'), + ReplSet = require('../../../../lib/core/topologies/replset'), mock = require('mongodb-mock-server'), genClusterTime = require('../common').genClusterTime, ReplSetFixture = require('../common').ReplSetFixture; diff --git a/test/core/unit/replset/step_down_tests.js b/test/core/unit/replset/step_down_tests.js index fcff830e15..3fde1b28e8 100644 --- a/test/core/unit/replset/step_down_tests.js +++ b/test/core/unit/replset/step_down_tests.js @@ -1,7 +1,7 @@ 'use strict'; const expect = require('chai').expect; -const ReplSet = require('../../../../lib/topologies/replset'); +const ReplSet = require('../../../../lib/core/topologies/replset'); const mock = require('mongodb-mock-server'); const ReplSetFixture = require('../common').ReplSetFixture; diff --git a/test/core/unit/replset/transactions_feature_decoration_tests.js b/test/core/unit/replset/transactions_feature_decoration_tests.js index 78706de399..6980841634 100644 --- a/test/core/unit/replset/transactions_feature_decoration_tests.js +++ b/test/core/unit/replset/transactions_feature_decoration_tests.js @@ -1,11 +1,13 @@ 'use strict'; const expect = require('chai').expect; -const ReplSet = require('../../../../lib/topologies/replset'); const mock = require('mongodb-mock-server'); const ReplSetFixture = require('../common').ReplSetFixture; -const ClientSession = require('../../../../lib/sessions').ClientSession; -const ServerSessionPool = require('../../../../lib/sessions').ServerSessionPool; + +const core = require('../../../../lib/core'); +const ReplSet = core.ReplSet; +const ClientSession = core.Sessions.ClientSession; +const ServerSessionPool = core.Sessions.ServerSessionPool; describe('Transaction Feature Decoration', function() { let test; @@ -84,9 +86,15 @@ describe('Transaction Feature Decoration', function() { } ); + const sessionPool = new ServerSessionPool(replSet); + const session = new ClientSession(replSet, sessionPool, {}, {}); + function shutdown(err) { replSet.destroy(); - done(err); + session.endSession(() => { + sessionPool.endAllPooledSessions(); + done(err); + }); } test.primaryServer.setMessageHandler(request => { @@ -113,8 +121,7 @@ describe('Transaction Feature Decoration', function() { } }); - const sessionPool = new ServerSessionPool(replSet); - + replSet.on('error', shutdown); replSet.on('connect', () => { const options = {}; @@ -123,8 +130,7 @@ describe('Transaction Feature Decoration', function() { } if (config.session) { - options.session = new ClientSession(replSet, sessionPool, {}, {}); - + options.session = session; if (config.transaction) { options.session.startTransaction(); } @@ -133,8 +139,6 @@ describe('Transaction Feature Decoration', function() { replSet[config.fnName](ns, config.arg, options, noop); }); - replSet.on('error', shutdown); - replSet.connect(); } }); diff --git a/test/core/unit/response_test.js b/test/core/unit/response_test.js index d516a50329..8d49145d31 100644 --- a/test/core/unit/response_test.js +++ b/test/core/unit/response_test.js @@ -1,9 +1,9 @@ 'use strict'; const expect = require('chai').expect; -const MongoError = require('../../../lib/error').MongoError; +const MongoError = require('../../../lib/core/error').MongoError; const mock = require('mongodb-mock-server'); -const Server = require('../../../lib/topologies/server'); +const Server = require('../../../lib/core/topologies/server'); const Long = require('bson').Long; const test = {}; diff --git a/test/core/unit/scram_iterations_tests.js b/test/core/unit/scram_iterations_tests.js index 77ca55b4c8..29ea25ff5c 100644 --- a/test/core/unit/scram_iterations_tests.js +++ b/test/core/unit/scram_iterations_tests.js @@ -2,9 +2,9 @@ const expect = require('chai').expect; const mock = require('mongodb-mock-server'); -const Server = require('../../../lib/topologies/server'); +const Server = require('../../../lib/core/topologies/server'); const Buffer = require('safe-buffer').Buffer; -const MongoCredentials = require('../../../lib/auth/mongo_credentials').MongoCredentials; +const MongoCredentials = require('../../../lib/core/auth/mongo_credentials').MongoCredentials; describe('SCRAM Iterations Tests', function() { const test = {}; diff --git a/test/core/unit/sdam_spec_tests.js b/test/core/unit/sdam_spec_tests.js index 5ba351211c..bf3e029986 100644 --- a/test/core/unit/sdam_spec_tests.js +++ b/test/core/unit/sdam_spec_tests.js @@ -3,11 +3,11 @@ const fs = require('fs'); const path = require('path'); const chai = require('chai'); const expect = chai.expect; -const Topology = require('../../../lib/sdam/topology'); -const Server = require('../../../lib/sdam/server'); -const ServerDescription = require('../../../lib/sdam/server_description').ServerDescription; -const monitoring = require('../../../lib/sdam/monitoring'); -const parse = require('../../../lib/uri_parser'); +const Topology = require('../../../lib/core/sdam/topology'); +const Server = require('../../../lib/core/sdam/server'); +const ServerDescription = require('../../../lib/core/sdam/server_description').ServerDescription; +const monitoring = require('../../../lib/core/sdam/monitoring'); +const parse = require('../../../lib/core/uri_parser'); chai.use(require('chai-subset')); const sinon = require('sinon'); diff --git a/test/core/unit/server_selection_spec_tests.js b/test/core/unit/server_selection_spec_tests.js index 50f0c23ed4..b0728b73aa 100644 --- a/test/core/unit/server_selection_spec_tests.js +++ b/test/core/unit/server_selection_spec_tests.js @@ -1,13 +1,13 @@ 'use strict'; const path = require('path'); const fs = require('fs'); -const Topology = require('../../../lib/sdam/topology'); -const Server = require('../../../lib/sdam/server'); -const ServerDescription = require('../../../lib/sdam/server_description').ServerDescription; -const ServerType = require('../../../lib/sdam/server_description').ServerType; -const ServerSelectors = require('../../../lib/sdam/server_selectors'); -const MongoTimeoutError = require('../../../lib/error').MongoTimeoutError; -const ReadPreference = require('../../../lib/topologies/read_preference'); +const Topology = require('../../../lib/core/sdam/topology'); +const Server = require('../../../lib/core/sdam/server'); +const ServerDescription = require('../../../lib/core/sdam/server_description').ServerDescription; +const ServerType = require('../../../lib/core/sdam/server_description').ServerType; +const ServerSelectors = require('../../../lib/core/sdam/server_selectors'); +const MongoTimeoutError = require('../../../lib/core/error').MongoTimeoutError; +const ReadPreference = require('../../../lib/core/topologies/read_preference'); const EJSON = require('mongodb-extjson'); const sinon = require('sinon'); @@ -270,7 +270,7 @@ function executeServerSelectionTest(testDefinition, options, testDone) { } } - // default to serverSelectionTimeoutMS of `0` for unit tests + // default to serverSelectionTimeoutMS of `100` for unit tests topology.selectServer(selector, { serverSelectionTimeoutMS: 100 }, (err, server) => { // are we expecting an error? if (testDefinition.error) { diff --git a/test/core/unit/sessions_tests.js b/test/core/unit/sessions_tests.js index eaa4c2ff85..bf58185ba4 100644 --- a/test/core/unit/sessions_tests.js +++ b/test/core/unit/sessions_tests.js @@ -1,12 +1,15 @@ 'use strict'; -const Server = require('../../..').Server, - mock = require('mongodb-mock-server'), - expect = require('chai').expect, - ServerSessionPool = require('../../../lib/sessions').ServerSessionPool, - ServerSession = require('../../../lib/sessions').ServerSession, - ClientSession = require('../../../lib/sessions').ClientSession, - genClusterTime = require('./common').genClusterTime; +const mock = require('mongodb-mock-server'); +const expect = require('chai').expect; +const genClusterTime = require('./common').genClusterTime; +const sessionCleanupHandler = require('./common').sessionCleanupHandler; + +const core = require('../../../lib/core'); +const Server = core.Server; +const ServerSessionPool = core.Sessions.ServerSessionPool; +const ServerSession = core.Sessions.ServerSession; +const ClientSession = core.Sessions.ClientSession; let test = {}; describe('Sessions', function() { @@ -30,22 +33,28 @@ describe('Sessions', function() { it('should default to `null` for `clusterTime`', { metadata: { requires: { topology: 'single' } }, - test: function() { + test: function(done) { const client = new Server(); const sessionPool = new ServerSessionPool(client); const session = new ClientSession(client, sessionPool); + done = sessionCleanupHandler(session, sessionPool, done); + expect(session.clusterTime).to.not.exist; + done(); } }); it('should set the internal clusterTime to `initialClusterTime` if provided', { metadata: { requires: { topology: 'single' } }, - test: function() { + test: function(done) { const clusterTime = genClusterTime(Date.now()); const client = new Server(); const sessionPool = new ServerSessionPool(client); const session = new ClientSession(client, sessionPool, { initialClusterTime: clusterTime }); + done = sessionCleanupHandler(session, sessionPool, done); + expect(session.clusterTime).to.eql(clusterTime); + done(); } }); }); @@ -94,10 +103,14 @@ describe('Sessions', function() { metadata: { requires: { topology: 'single' } }, test: function(done) { const pool = new ServerSessionPool(test.client); + done = sessionCleanupHandler(null, pool, done); expect(pool.sessions).to.have.length(0); + const session = pool.acquire(); expect(session).to.exist; expect(pool.sessions).to.have.length(0); + pool.release(session); + done(); } }); @@ -108,11 +121,13 @@ describe('Sessions', function() { test: function(done) { const oldSession = new ServerSession(); const pool = new ServerSessionPool(test.client); + done = sessionCleanupHandler(null, pool, done); pool.sessions.push(oldSession); const session = pool.acquire(); expect(session).to.exist; expect(session).to.eql(oldSession); + pool.release(session); done(); } @@ -126,11 +141,13 @@ describe('Sessions', function() { oldSession.lastUse = new Date(Date.now() - 30 * 60 * 1000).getTime(); // add 30min const pool = new ServerSessionPool(test.client); + done = sessionCleanupHandler(null, pool, done); pool.sessions.push(oldSession); const session = pool.acquire(); expect(session).to.exist; expect(session).to.not.eql(oldSession); + pool.release(session); done(); } @@ -147,6 +164,7 @@ describe('Sessions', function() { }); const pool = new ServerSessionPool(test.client); + done = sessionCleanupHandler(null, pool, done); pool.sessions = pool.sessions.concat(oldSessions); pool.release(newSession); @@ -164,6 +182,8 @@ describe('Sessions', function() { session.lastUse = new Date(Date.now() - 9.5 * 60 * 1000).getTime(); // add 9.5min const pool = new ServerSessionPool(test.client); + done = sessionCleanupHandler(null, pool, done); + pool.release(session); expect(pool.sessions).to.have.length(0); done(); @@ -174,6 +194,7 @@ describe('Sessions', function() { metadata: { requires: { topology: 'single' } }, test: function(done) { const pool = new ServerSessionPool(test.client); + done = sessionCleanupHandler(null, pool, done); const sessionA = new ServerSession(); const sessionB = new ServerSession(); @@ -186,6 +207,9 @@ describe('Sessions', function() { expect(sessionC.id).to.eql(sessionB.id); expect(sessionD.id).to.eql(sessionA.id); + + pool.release(sessionC); + pool.release(sessionD); done(); } }); diff --git a/test/core/unit/single/sessions_tests.js b/test/core/unit/single/sessions_tests.js index a32cb7ad9a..3e90b2f396 100644 --- a/test/core/unit/single/sessions_tests.js +++ b/test/core/unit/single/sessions_tests.js @@ -1,13 +1,16 @@ 'use strict'; -var Server = require('../../../../lib/topologies/server'), - Long = require('bson').Long, - ObjectId = require('bson').ObjectId, - Timestamp = require('bson').Timestamp, - expect = require('chai').expect, - mock = require('mongodb-mock-server'), - genClusterTime = require('../common').genClusterTime, - ClientSession = require('../../../../lib/sessions').ClientSession, - ServerSessionPool = require('../../../../lib/sessions').ServerSessionPool; +const expect = require('chai').expect; +const mock = require('mongodb-mock-server'); +const genClusterTime = require('../common').genClusterTime; +const sessionCleanupHandler = require('../common').sessionCleanupHandler; + +const core = require('../../../../lib/core'); +const Server = core.Server; +const Long = core.BSON.Long; +const ObjectId = core.BSON.ObjectId; +const Timestamp = core.BSON.Timestamp; +const ClientSession = core.Sessions.ClientSession; +const ServerSessionPool = core.Sessions.ServerSessionPool; const test = {}; describe('Sessions (Single)', function() { @@ -89,7 +92,7 @@ describe('Sessions (Single)', function() { it('should track the highest `$clusterTime` seen, and store it on a session if available', { metadata: { requires: { topology: 'single' } }, - test: function(done) { + test: function(_done) { const clusterTime = genClusterTime(Date.now()), futureClusterTime = genClusterTime(Date.now() + 10 * 60 * 1000); @@ -114,6 +117,7 @@ describe('Sessions (Single)', function() { const client = new Server(test.server.address()); const sessionPool = new ServerSessionPool(client); const session = new ClientSession(client, sessionPool); + const done = sessionCleanupHandler(session, sessionPool, _done); client.on('error', done); client.once('connect', () => { @@ -166,6 +170,7 @@ describe('Sessions (Single)', function() { expect(err).to.not.exist; expect(command.$clusterTime).to.eql(clusterTime); + client.destroy(); done(); }); }); @@ -176,7 +181,7 @@ describe('Sessions (Single)', function() { it('should send the highest `clusterTime` between topology and session if it exists', { metadata: { requires: { topology: 'single' } }, - test: function(done) { + test: function(_done) { const clusterTime = genClusterTime(Date.now()), futureClusterTime = genClusterTime(Date.now() + 10 * 60 * 1000); @@ -204,11 +209,14 @@ describe('Sessions (Single)', function() { initialClusterTime: futureClusterTime }); + const done = sessionCleanupHandler(session, sessionPool, _done); + client.on('error', done); client.once('connect', () => { client.command('admin.$cmd', { ping: 1 }, { session: session }, err => { expect(err).to.not.exist; expect(command.$clusterTime).to.eql(futureClusterTime); + client.destroy(); done(); }); }); @@ -219,7 +227,7 @@ describe('Sessions (Single)', function() { it('should return server sessions to the pool on `endSession`', { metadata: { requires: { topology: 'single' } }, - test: function(done) { + test: function(_done) { let sentIsMaster = false; test.server.setMessageHandler(request => { if (sentIsMaster) { @@ -240,6 +248,7 @@ describe('Sessions (Single)', function() { const sessionPool = new ServerSessionPool(client); const session = new ClientSession(client, sessionPool); const clientServerSession = session.serverSession; + const done = sessionCleanupHandler(session, sessionPool, _done); client.on('error', done); client.once('connect', () => { @@ -252,6 +261,7 @@ describe('Sessions (Single)', function() { expect(sessionPool.sessions).to.have.length(1); expect(sessionPool.sessions[0]).to.eql(clientServerSession); + client.destroy(); done(); }); }); @@ -296,11 +306,12 @@ describe('Sessions (Single)', function() { 'should add `lsid` to commands sent to the server, and update the session `lastUse` when a session is provided', { metadata: { requires: { topology: 'single' } }, - test: function(done) { + test: function(_done) { const client = new Server(test.server.address()); const sessionPool = new ServerSessionPool(client); const session = new ClientSession(client, sessionPool); const initialLastUse = session.serverSession.lastUse; + const done = sessionCleanupHandler(session, sessionPool, _done); let sentIsMaster = false, command = null; @@ -329,6 +340,7 @@ describe('Sessions (Single)', function() { expect(command.lsid).to.eql(session.id); expect(session.serverSession.lastUse).to.not.eql(initialLastUse); + client.destroy(); done(); }); }, 250); @@ -341,10 +353,11 @@ describe('Sessions (Single)', function() { it('should use the same session for all getMore issued by a cursor', { metadata: { requires: { topology: 'single' } }, - test: function(done) { + test: function(_done) { const client = new Server(test.server.address()); const sessionPool = new ServerSessionPool(client); const session = new ClientSession(client, sessionPool); + const done = sessionCleanupHandler(session, sessionPool, _done); let commands = []; test.server.setMessageHandler(request => { @@ -413,10 +426,11 @@ describe('Sessions (Single)', function() { it('should use the same session for any killCursor issued by a cursor', { metadata: { requires: { topology: 'single' } }, - test: function(done) { + test: function(_done) { const client = new Server(test.server.address()); const sessionPool = new ServerSessionPool(client); const session = new ClientSession(client, sessionPool); + const done = sessionCleanupHandler(session, sessionPool, _done); let commands = []; test.server.setMessageHandler(request => { @@ -487,10 +501,11 @@ describe('Sessions (Single)', function() { it('should not hang on endSession when topology is closed', { metadata: { requires: { topology: 'single' } }, - test: function(done) { + test: function(_done) { const client = new Server(test.server.address()); const sessionPool = new ServerSessionPool(client); const session = new ClientSession(client, sessionPool); + const done = sessionCleanupHandler(session, sessionPool, _done); test.server.setMessageHandler(request => { const doc = request.document; @@ -515,10 +530,11 @@ describe('Sessions (Single)', function() { it('should not allow use of an expired session', { metadata: { requires: { topology: 'single' } }, - test: function(done) { + test: function(_done) { const client = new Server(test.server.address()); const sessionPool = new ServerSessionPool(client); const session = new ClientSession(client, sessionPool); + const done = sessionCleanupHandler(session, sessionPool, _done); test.server.setMessageHandler(request => { const doc = request.document; @@ -538,6 +554,8 @@ describe('Sessions (Single)', function() { session.endSession(() => { client.command('admin.$cmd', { ping: 1 }, { session: session }, err => { expect(err).to.exist; + + client.destroy(); done(); }); }); @@ -549,11 +567,12 @@ describe('Sessions (Single)', function() { it.skip('should not allow use of session object across clients', { metadata: { requires: { topology: 'single' } }, - test: function(done) { + test: function(_done) { const client = new Server(test.server.address()); const client2 = new Server(test.server.address()); const sessionPool = new ServerSessionPool(client); const session = new ClientSession(client, sessionPool); + const done = sessionCleanupHandler(session, sessionPool, _done); test.server.setMessageHandler(request => { const doc = request.document; @@ -584,12 +603,13 @@ describe('Sessions (Single)', function() { it('should track the highest `operationTime` seen, if causal consistency is enabled', { metadata: { requires: { topology: 'single' } }, - test: function(done) { + test: function(_done) { const client = new Server(test.server.address()), sessionPool = new ServerSessionPool(client), session = new ClientSession(client, sessionPool, { causalConsistency: true }), insertOperationTime1 = Timestamp.fromNumber(Date.now()), insertOperationTime2 = Timestamp.fromNumber(Date.now() + 10 * 60 * 1000); + const done = sessionCleanupHandler(session, sessionPool, _done); let insertCount = 0; test.server.setMessageHandler(request => { @@ -630,10 +650,11 @@ describe('Sessions (Single)', function() { it('should emit an `ended` signal when the session is ended', { metadata: { requires: { topology: 'single' } }, - test: function(done) { + test: function(_done) { const client = new Server(test.server.address()); const sessionPool = new ServerSessionPool(client); const session = new ClientSession(client, sessionPool); + const done = sessionCleanupHandler(session, sessionPool, _done); test.server.setMessageHandler(request => { const doc = request.document; @@ -650,8 +671,14 @@ describe('Sessions (Single)', function() { client.on('error', done); client.once('connect', () => { - session.once('ended', () => done()); - session.endSession(); + let endedSignalReceived = false; + session.once('ended', () => (endedSignalReceived = true)); + session.endSession(() => { + expect(endedSignalReceived).to.be.true; + + client.destroy(); + done(); + }); }); client.connect(); diff --git a/test/core/unit/wire_protocol_test.js b/test/core/unit/wire_protocol_test.js index cb7797377d..0a0cca1d57 100644 --- a/test/core/unit/wire_protocol_test.js +++ b/test/core/unit/wire_protocol_test.js @@ -4,8 +4,8 @@ const chai = require('chai'); const expect = chai.expect; const bson = require('bson'); const sinon = require('sinon'); -const Pool = require('../../../lib/connection/pool.js'); -const wireProtocol = require('../../../lib/wireprotocol'); +const Pool = require('../../../lib/core/connection/pool.js'); +const wireProtocol = require('../../../lib/core/wireprotocol'); describe('WireProtocol', function() { it('should only set bypassDocumentValidation to true if explicitly set by user to true', function() { diff --git a/test/core/unit/write_concern_error_tests.js b/test/core/unit/write_concern_error_tests.js index dbb30cd03c..352391836c 100644 --- a/test/core/unit/write_concern_error_tests.js +++ b/test/core/unit/write_concern_error_tests.js @@ -1,8 +1,8 @@ 'use strict'; -const ReplSet = require('../../../lib/topologies/replset'); +const ReplSet = require('../../../lib/core/topologies/replset'); const mock = require('mongodb-mock-server'); const ReplSetFixture = require('./common').ReplSetFixture; -const MongoWriteConcernError = require('../../../lib/error').MongoWriteConcernError; +const MongoWriteConcernError = require('../../../lib/core/error').MongoWriteConcernError; const expect = require('chai').expect; describe('WriteConcernError', function() { diff --git a/test/environments.js b/test/environments.js index 5d41aa0065..73bebca2bd 100644 --- a/test/environments.js +++ b/test/environments.js @@ -4,11 +4,7 @@ const f = require('util').format; const semver = require('semver'); const path = require('path'); const EnvironmentBase = require('mongodb-test-runner').EnvironmentBase; - -// topologies -const Server = require('..').Server; -const ReplSet = require('..').ReplSet; -const Mongos = require('..').Mongos; +const core = require('../lib/core'); // topology managers const topologyManagers = require('mongodb-test-runner').topologyManagers; @@ -30,6 +26,10 @@ const genReplsetConfig = (port, options) => { ); }; +function usingUnifiedTopology() { + return !!process.env.MONGODB_UNIFIED_TOPOLOGY; +} + /** * * @param {*} discoverResult @@ -44,15 +44,19 @@ class ReplicaSetEnvironment extends EnvironmentBase { this.url = 'mongodb://%slocalhost:31000/integration_tests?rs_name=rs'; this.writeConcernMax = { w: 'majority', wtimeout: 30000 }; this.replicasetName = 'rs'; - this.topology = function(host, port, serverOptions) { + this.topology = function(host, port, options) { host = host || 'localhost'; port = port || 31000; - serverOptions = Object.assign({}, serverOptions); - serverOptions.rs_name = 'rs'; - serverOptions.poolSize = 1; - serverOptions.autoReconnect = false; + options = Object.assign({}, options); + options.replicaSet = 'rs'; + options.poolSize = 1; + options.autoReconnect = false; - return new ReplSet([new Server(host, port, serverOptions)], serverOptions); + if (usingUnifiedTopology()) { + return new core.Topology([{ host, port }], options); + } + + return new core.ReplSet([{ host, port }], options); }; this.nodes = [ @@ -134,11 +138,16 @@ class ShardedEnvironment extends EnvironmentBase { this.port = 51000; this.url = 'mongodb://%slocalhost:51000,localhost:51001/integration_tests'; this.writeConcernMax = { w: 'majority', wtimeout: 30000 }; - this.topology = function(host, port, options) { - options = options || {}; - options.autoReconnect = false; + this.topology = (host, port /*, options */) => { + host = host || 'localhost'; + port = port || 51000; + // options = options || {}; + + if (usingUnifiedTopology()) { + return new core.Topology([{ host, port }]); + } - return new Mongos([new Server(host, port, options)], options); + return new core.Mongos([{ host, port }]); }; const version = @@ -220,7 +229,7 @@ class SslEnvironment extends EnvironmentBase { serverOptions.poolSize = 1; serverOptions.ssl = true; serverOptions.sslValidate = false; - return new Server(host, port, serverOptions); + return new core.Server(host, port, serverOptions); }; this.manager = new ServerManager('mongod', { @@ -245,7 +254,7 @@ class AuthEnvironment extends EnvironmentBase { port = port || 27017; serverOptions = Object.assign({}, serverOptions); serverOptions.poolSize = 1; - return new Server(host, port, serverOptions); + return new core.Server(host, port, serverOptions); }; this.manager = new ServerManager('mongod', { diff --git a/test/functional/change_stream_tests.js b/test/functional/change_stream_tests.js index 6133c8a5dd..3ce57fabda 100644 --- a/test/functional/change_stream_tests.js +++ b/test/functional/change_stream_tests.js @@ -1,7 +1,7 @@ 'use strict'; var assert = require('assert'); var Transform = require('stream').Transform; -var MongoNetworkError = require('mongodb-core').MongoNetworkError; +var MongoNetworkError = require('../../lib/core').MongoNetworkError; var setupDatabase = require('./shared').setupDatabase; var delay = require('./shared').delay; var co = require('co'); diff --git a/test/functional/cursor_tests.js b/test/functional/cursor_tests.js index fd027175b7..4ab298c2a0 100644 --- a/test/functional/cursor_tests.js +++ b/test/functional/cursor_tests.js @@ -5,9 +5,11 @@ const fs = require('fs'); const expect = require('chai').expect; const Long = require('bson').Long; const sinon = require('sinon'); -const ReadPreference = require('mongodb-core').ReadPreference; const Buffer = require('safe-buffer').Buffer; +const core = require('../../lib/core'); +const ReadPreference = core.ReadPreference; + describe('Cursor', function() { before(function() { return setupDatabase(this.configuration, [ @@ -4545,7 +4547,6 @@ describe('Cursor', function() { it('should apply parent read preference to count command', function(done) { const configuration = this.configuration; - const ReadPreference = this.configuration.require.ReadPreference; const client = configuration.newClient( { w: 1, readPreference: ReadPreference.SECONDARY }, { poolSize: 1, auto_reconnect: false, connectWithNoPrimary: true } diff --git a/test/functional/raw_tests.js b/test/functional/raw_tests.js index 33eda59880..7763590a06 100644 --- a/test/functional/raw_tests.js +++ b/test/functional/raw_tests.js @@ -3,7 +3,7 @@ var test = require('./shared').assert; var setupDatabase = require('./shared').setupDatabase; var Buffer = require('buffer').Buffer; -var BSON = require('mongodb-core').BSON; +var BSON = require('../../lib/core').BSON; var bson = new BSON([ BSON.Binary, BSON.Code, diff --git a/test/functional/replset_connection_tests.js b/test/functional/replset_connection_tests.js index e05462ef1d..f2bd278bb2 100644 --- a/test/functional/replset_connection_tests.js +++ b/test/functional/replset_connection_tests.js @@ -862,7 +862,7 @@ describe.skip('ReplSet (Connection)', function() { }); var waitForPrimary = function(count, config, options, callback) { - var ReplSet = require('mongodb-core').ReplSet; + var ReplSet = require('../../lib/core').ReplSet; if (count === 0) return callback(new Error('could not connect')); // Attempt to connect var server = new ReplSet(config, options); diff --git a/test/functional/scram_sha_256_tests.js b/test/functional/scram_sha_256_tests.js index 11b3f51462..ff13ddbff2 100644 --- a/test/functional/scram_sha_256_tests.js +++ b/test/functional/scram_sha_256_tests.js @@ -2,7 +2,7 @@ const expect = require('chai').expect; const sinon = require('sinon'); -const ScramSHA256 = require('mongodb-core').ScramSHA256; +const ScramSHA256 = require('../../lib/core').ScramSHA256; const setupDatabase = require('./shared').setupDatabase; const withClient = require('./shared').withClient; diff --git a/test/functional/session_leak_test.js b/test/functional/session_leak_test.js index e27bcca6ea..c06ab8afe6 100644 --- a/test/functional/session_leak_test.js +++ b/test/functional/session_leak_test.js @@ -2,7 +2,7 @@ const expect = require('chai').expect; const sinon = require('sinon'); -const core = require('mongodb-core'); +const core = require('../../lib/core'); const MongoClient = require('../../lib/mongo_client'); const ServerSessionPool = core.Sessions.ServerSessionPool; diff --git a/test/functional/transactions_tests.js b/test/functional/transactions_tests.js index ce725f7f8c..32dd818bd8 100644 --- a/test/functional/transactions_tests.js +++ b/test/functional/transactions_tests.js @@ -6,7 +6,7 @@ const fs = require('fs'); const chai = require('chai'); const expect = chai.expect; const EJSON = require('mongodb-extjson'); -const core = require('mongodb-core'); +const core = require('../../lib/core'); const sessions = core.Sessions; const environments = require('../environments'); diff --git a/test/functional/uri_options_spec_tests.js b/test/functional/uri_options_spec_tests.js index 0197279a69..a5954b96ca 100644 --- a/test/functional/uri_options_spec_tests.js +++ b/test/functional/uri_options_spec_tests.js @@ -4,8 +4,10 @@ const fs = require('fs'); const chai = require('chai'); const expect = chai.expect; chai.use(require('chai-subset')); -const parse = require('mongodb-core').parseConnectionString; -const MongoParseError = require('mongodb-core').MongoParseError; + +const core = require('../../lib/core'); +const parse = core.parseConnectionString; +const MongoParseError = core.MongoParseError; describe('URI Options (spec)', function() { fs diff --git a/test/functional/url_parser_tests.js b/test/functional/url_parser_tests.js index 300fc6c096..df25d45a90 100644 --- a/test/functional/url_parser_tests.js +++ b/test/functional/url_parser_tests.js @@ -645,6 +645,7 @@ describe('Url Parser', function() { Logger = self.configuration.require.Logger, logged = false; + const logger = Logger.currentLogger(); Logger.setCurrentLogger(function(msg, context) { expect(msg).to.exist; expect(msg).to.contain('not supported'); @@ -665,14 +666,14 @@ describe('Url Parser', function() { expect(logged).to.be.true; parse('mongodb://localhost/db?uuidRepresentation=1', {}, function() { expect(logged).to.be.true; + + Logger.setCurrentLogger(logger); done(); }); }); }); }); }); - - Logger.reset(); } }); diff --git a/test/tools/utils.js b/test/tools/utils.js index 8955aa9054..ec8826d88d 100644 --- a/test/tools/utils.js +++ b/test/tools/utils.js @@ -1,6 +1,6 @@ 'use strict'; -const Logger = require('mongodb-core').Logger; +const Logger = require('../../lib/core').Logger; const deprecateOptions = require('../../lib/utils').deprecateOptions; const chai = require('chai'); const expect = chai.expect; diff --git a/test/unit/change_stream_resume_tests.js b/test/unit/change_stream_resume_tests.js index a3999f1f01..5df195df07 100644 --- a/test/unit/change_stream_resume_tests.js +++ b/test/unit/change_stream_resume_tests.js @@ -180,7 +180,7 @@ describe('Change Stream Resume Tests', function() { configs.forEach(config => { it(config.description, { - metadata: { requires: { mongodb: '>=3.6.0' } }, + metadata: { requires: { topology: 'single' } }, test: function() { const configuration = this.configuration; test.server.setMessageHandler(makeServerHandler(config)); diff --git a/test/unit/db_tests.js b/test/unit/db_tests.js index 3bc02d961a..d683763f68 100644 --- a/test/unit/db_tests.js +++ b/test/unit/db_tests.js @@ -12,6 +12,10 @@ class MockTopology extends EventEmitter { }; } + isDestroyed() { + return false; + } + capabilities() { return {}; } @@ -19,6 +23,10 @@ class MockTopology extends EventEmitter { hasSessionSupport() { return false; } + + command(namespace, command, options, callback) { + callback(null, { ok: 1 }); + } } const test = {};