diff --git a/lib/connection_string.js b/lib/connection_string.js index ceda32d6e54..01789218aa4 100644 --- a/lib/connection_string.js +++ b/lib/connection_string.js @@ -37,6 +37,10 @@ function matchesParentDomain(srvAddress, parentDomain) { function parseSrvConnectionString(uri, options, callback) { const result = URL.parse(uri, true); + if (options.directConnection) { + return callback(new MongoParseError('directConnection not supported with SRV URI')); + } + if (result.hostname.split('.').length < 3) { return callback(new MongoParseError('URI does not have hostname, domain name and tld')); } @@ -217,7 +221,8 @@ const CASE_TRANSLATION = { tlscertificatekeyfile: 'tlsCertificateKeyFile', tlscertificatekeyfilepassword: 'tlsCertificateKeyFilePassword', wtimeout: 'wTimeoutMS', - j: 'journal' + j: 'journal', + directconnection: 'directConnection' }; /** @@ -594,10 +599,6 @@ function parseConnectionString(uri, options, callback) { return callback(new MongoParseError('Invalid protocol provided')); } - if (protocol === PROTOCOL_MONGODB_SRV) { - return parseSrvConnectionString(uri, options, callback); - } - const dbAndQuery = cap[4].split('?'); const db = dbAndQuery.length > 0 ? dbAndQuery[0] : null; const query = dbAndQuery.length > 1 ? dbAndQuery[1] : null; @@ -613,6 +614,12 @@ function parseConnectionString(uri, options, callback) { return callback(parseError); } + parsedOptions = Object.assign({}, parsedOptions, options); + + if (protocol === PROTOCOL_MONGODB_SRV) { + return parseSrvConnectionString(uri, parsedOptions, callback); + } + const auth = { username: null, password: null, db: db && db !== '' ? qs.unescape(db) : null }; if (parsedOptions.auth) { // maintain support for legacy options passed into `MongoClient` @@ -706,6 +713,13 @@ function parseConnectionString(uri, options, callback) { return callback(new MongoParseError('No hostname or hostnames provided in connection string')); } + const directConnection = !!parsedOptions.directConnection; + if (directConnection && hosts.length !== 1) { + // If the option is set to true, the driver MUST validate that there is exactly one host given + // in the host list in the URI, and fail client creation otherwise. + return callback(new MongoParseError('directConnection option requires exactly one host')); + } + const result = { hosts: hosts, auth: auth.db || auth.username ? auth : null, diff --git a/lib/mongo_client.js b/lib/mongo_client.js index f3984ccb75e..e481f6de868 100644 --- a/lib/mongo_client.js +++ b/lib/mongo_client.js @@ -102,7 +102,7 @@ const { connect, validOptions } = require('./operations/connect'); * @param {number} [options.reconnectInterval=1000] Server will wait # milliseconds between retries * @param {boolean} [options.ha=true] Control if high availability monitoring runs for Replicaset or Mongos proxies * @param {number} [options.haInterval=10000] The High availability period for replicaset inquiry - * @param {string} [options.replicaSet=undefined] The Replicaset set name + * @param {string} [options.replicaSet] The name of the replica set to connect to * @param {number} [options.secondaryAcceptableLatencyMS=15] Cutoff latency point in MS for Replicaset member selection * @param {number} [options.acceptableLatencyMS=15] Cutoff latency point in MS for Mongos proxies selection * @param {boolean} [options.connectWithNoPrimary=false] Sets if the driver should connect even if no primary is available @@ -142,6 +142,7 @@ const { connect, validOptions } = require('./operations/connect'); * @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections * @param {boolean} [options.useNewUrlParser=true] Determines whether or not to use the new url parser. Enables the new, spec-compliant, url parser shipped in the core driver. This url parser fixes a number of problems with the original parser, and aims to outright replace that parser in the near future. Defaults to true, and must be explicitly set to false to use the legacy url parser. * @param {DriverInfoOptions} [options.driverInfo] Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver + * @param {boolean} [options.directConnection=false] Whether to connect to the deployment in Single topology. * @param {AutoEncrypter~AutoEncryptionOptions} [options.autoEncryption] Optionally enable client side auto encryption * @returns {MongoClient} a MongoClient instance */ @@ -352,7 +353,7 @@ MongoClient.prototype.isConnected = function(options) { * @param {number} [options.reconnectInterval=1000] Server will wait # milliseconds between retries * @param {boolean} [options.ha=true] Control if high availability monitoring runs for Replicaset or Mongos proxies * @param {number} [options.haInterval=10000] The High availability period for replicaset inquiry - * @param {string} [options.replicaSet=undefined] The Replicaset set name + * @param {string} [options.replicaSet] The name of the replica set to connect to * @param {number} [options.secondaryAcceptableLatencyMS=15] Cutoff latency point in MS for Replicaset member selection * @param {number} [options.acceptableLatencyMS=15] Cutoff latency point in MS for Mongos proxies selection * @param {boolean} [options.connectWithNoPrimary=false] Sets if the driver should connect even if no primary is available @@ -388,6 +389,7 @@ MongoClient.prototype.isConnected = function(options) { * @param {number} [options.numberOfRetries=5] The number of retries for a tailable cursor * @param {boolean} [options.auto_reconnect=true] Enable auto reconnecting for single server instances * @param {number} [options.minSize] If present, the connection pool will be initialized with minSize connections, and will never dip below minSize connections + * @param {boolean} [options.directConnection=false] Whether to connect to the deployment in Single topology. * @param {MongoClient~connectCallback} [callback] The command result callback * @returns {Promise} returns Promise if no callback passed */ diff --git a/lib/operations/connect.js b/lib/operations/connect.js index a4802bda0cf..7df84454f40 100644 --- a/lib/operations/connect.js +++ b/lib/operations/connect.js @@ -111,7 +111,8 @@ const validOptionNames = [ 'tlsCertificateKeyFilePassword', 'minHeartbeatFrequencyMS', 'heartbeatFrequencyMS', - 'waitQueueTimeoutMS' + 'waitQueueTimeoutMS', + 'directConnection' ]; const ignoreOptionNames = ['native_parser']; diff --git a/lib/sdam/server_selection.js b/lib/sdam/server_selection.js index 071d4cc20ab..6286ab5d3a0 100644 --- a/lib/sdam/server_selection.js +++ b/lib/sdam/server_selection.js @@ -185,6 +185,10 @@ function readPreferenceServerSelector(readPreference) { ); } + if (topologyDescription.type === TopologyType.Unknown) { + return []; + } + if ( topologyDescription.type === TopologyType.Single || topologyDescription.type === TopologyType.Sharded diff --git a/lib/sdam/topology.js b/lib/sdam/topology.js index a9856650f19..d2604ab06c7 100644 --- a/lib/sdam/topology.js +++ b/lib/sdam/topology.js @@ -101,6 +101,8 @@ class Topology extends EventEmitter { * @param {number} [options.localThresholdMS=15] The size of the latency window for selecting among multiple suitable servers * @param {number} [options.serverSelectionTimeoutMS=30000] How long to block for server selection before throwing an error * @param {number} [options.heartbeatFrequencyMS=10000] The frequency with which topology updates are scheduled + * @param {boolean} [options.directConnection] Indicates that a client should directly connect to a node without attempting to discover its topology type + * @param {string} [options.replicaSet] The name of the replica set to connect to */ constructor(seedlist, options) { super(); @@ -136,7 +138,7 @@ class Topology extends EventEmitter { } }); - const topologyType = topologyTypeFromSeedlist(seedlist, options); + const topologyType = topologyTypeFromOptions(options); const topologyId = globalTopologyCounter++; const serverDescriptions = seedlist.reduce((result, seed) => { if (seed.domain_socket) seed.host = seed.domain_socket; @@ -797,10 +799,23 @@ function parseStringSeedlist(seedlist) { })); } -function topologyTypeFromSeedlist(seedlist, options) { - const replicaSet = options.replicaSet || options.setName || options.rs_name; - if (seedlist.length === 1 && !replicaSet) return TopologyType.Single; - if (replicaSet) return TopologyType.ReplicaSetNoPrimary; +/** + * Gets the TopologyType from the client options + * + * @param {object} options mongo client options + * @param {boolean} [options.directConnection] Indicates that a client should directly connect to a node without attempting to discover its topology type + * @param {string} [options.replicaSet] The name of the replica set to connect to + * @returns TopologyType + */ +function topologyTypeFromOptions(options) { + if (options.directConnection) { + return TopologyType.Single; + } + + if (options.replicaSet) { + return TopologyType.ReplicaSetNoPrimary; + } + return TopologyType.Unknown; } diff --git a/lib/sdam/topology_description.js b/lib/sdam/topology_description.js index e802469e8d5..fc4b489e477 100644 --- a/lib/sdam/topology_description.js +++ b/lib/sdam/topology_description.js @@ -163,7 +163,7 @@ class TopologyDescription { } if (topologyType === TopologyType.Unknown) { - if (serverType === ServerType.Standalone) { + if (serverType === ServerType.Standalone && this.servers.size !== 1) { serverDescriptions.delete(address); } else { topologyType = topologyTypeForServerType(serverType); @@ -277,9 +277,19 @@ class TopologyDescription { } function topologyTypeForServerType(serverType) { - if (serverType === ServerType.Mongos) return TopologyType.Sharded; - if (serverType === ServerType.RSPrimary) return TopologyType.ReplicaSetWithPrimary; - return TopologyType.ReplicaSetNoPrimary; + switch (serverType) { + case ServerType.Standalone: + return TopologyType.Single; + case ServerType.Mongos: + return TopologyType.Sharded; + case ServerType.RSPrimary: + return TopologyType.ReplicaSetWithPrimary; + case ServerType.RSOther: + case ServerType.RSSecondary: + return TopologyType.ReplicaSetNoPrimary; + default: + return TopologyType.Unknown; + } } function compareObjectId(oid1, oid2) { diff --git a/test/spec/initial-dns-seedlist-discovery/direct-connection-false.json b/test/spec/initial-dns-seedlist-discovery/direct-connection-false.json new file mode 100644 index 00000000000..01560d5acc4 --- /dev/null +++ b/test/spec/initial-dns-seedlist-discovery/direct-connection-false.json @@ -0,0 +1,14 @@ +{ + "uri": "mongodb+srv://test3.test.build.10gen.cc/?directConnection=false", + "seeds": [ + "localhost.test.build.10gen.cc:27017" + ], + "hosts": [ + "localhost:27017", + "localhost:27018", + "localhost:27019" + ], + "options": { + "ssl": true + } +} diff --git a/test/spec/initial-dns-seedlist-discovery/direct-connection-false.yml b/test/spec/initial-dns-seedlist-discovery/direct-connection-false.yml new file mode 100644 index 00000000000..6bc97e075fd --- /dev/null +++ b/test/spec/initial-dns-seedlist-discovery/direct-connection-false.yml @@ -0,0 +1,9 @@ +uri: "mongodb+srv://test3.test.build.10gen.cc/?directConnection=false" +seeds: + - localhost.test.build.10gen.cc:27017 +hosts: + - localhost:27017 + - localhost:27018 + - localhost:27019 +options: + ssl: true diff --git a/test/spec/initial-dns-seedlist-discovery/direct-connection-true.json b/test/spec/initial-dns-seedlist-discovery/direct-connection-true.json new file mode 100644 index 00000000000..ace6700106e --- /dev/null +++ b/test/spec/initial-dns-seedlist-discovery/direct-connection-true.json @@ -0,0 +1,7 @@ +{ + "uri": "mongodb+srv://test3.test.build.10gen.cc/?directConnection=true", + "seeds": [], + "hosts": [], + "error": true, + "comment": "Should fail because directConnection=true is incompatible with SRV URIs." +} diff --git a/test/spec/initial-dns-seedlist-discovery/direct-connection-true.yml b/test/spec/initial-dns-seedlist-discovery/direct-connection-true.yml new file mode 100644 index 00000000000..923e4e67538 --- /dev/null +++ b/test/spec/initial-dns-seedlist-discovery/direct-connection-true.yml @@ -0,0 +1,5 @@ +uri: "mongodb+srv://test3.test.build.10gen.cc/?directConnection=true" +seeds: [] +hosts: [] +error: true +comment: Should fail because directConnection=true is incompatible with SRV URIs. diff --git a/test/spec/server-discovery-and-monitoring/rs/compatible.yml b/test/spec/server-discovery-and-monitoring/rs/compatible.yml index 3e041d60305..6fade62db94 100644 --- a/test/spec/server-discovery-and-monitoring/rs/compatible.yml +++ b/test/spec/server-discovery-and-monitoring/rs/compatible.yml @@ -1,5 +1,7 @@ description: "Replica set member with large maxWireVersion" + uri: "mongodb://a,b/?replicaSet=rs" + phases: [ { responses: [ diff --git a/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.yml b/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.yml index c1cb73aceb1..b36b69dd4a4 100644 --- a/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.yml +++ b/test/spec/server-discovery-and-monitoring/rs/compatible_unknown.yml @@ -1,5 +1,7 @@ description: "Replica set member and an unknown server" + uri: "mongodb://a,b/?replicaSet=rs" + phases: [ { responses: [ diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.json b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.json index ced7baeb653..ad337c127a2 100644 --- a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.json +++ b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.json @@ -1,6 +1,6 @@ { - "description": "Discover arbiters", - "uri": "mongodb://a/?replicaSet=rs", + "description": "Discover arbiters with directConnection URI option", + "uri": "mongodb://a/?directConnection=false", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.yml b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.yml index 831f9da0ed0..15cd0308d5e 100644 --- a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.yml +++ b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters.yml @@ -1,6 +1,6 @@ -description: "Discover arbiters" +description: "Discover arbiters with directConnection URI option" -uri: "mongodb://a/?replicaSet=rs" +uri: "mongodb://a/?directConnection=false" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.json new file mode 100644 index 00000000000..dc00dca5f00 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.json @@ -0,0 +1,41 @@ +{ + "description": "Discover arbiters with replicaSet URI option", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": true, + "hosts": [ + "a:27017" + ], + "arbiters": [ + "b:27017" + ], + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + }, + "b:27017": { + "type": "Unknown", + "setName": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.yml new file mode 100644 index 00000000000..c9255aa3efb --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_arbiters_replicaset.yml @@ -0,0 +1,43 @@ +description: "Discover arbiters with replicaSet URI option" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + { + responses: [ + + ["a:27017", { + + ok: 1, + ismaster: true, + hosts: ["a:27017"], + arbiters: ["b:27017"], + setName: "rs", + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "RSPrimary", + setName: "rs" + }, + + "b:27017": { + + type: "Unknown", + setName: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_ghost.json b/test/spec/server-discovery-and-monitoring/rs/discover_ghost.json new file mode 100644 index 00000000000..1e2ca91bcb4 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_ghost.json @@ -0,0 +1,31 @@ +{ + "description": "Discover ghost with directConnection URI option", + "uri": "mongodb://b/?directConnection=false", + "phases": [ + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "ismaster": false, + "isreplicaset": true, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "b:27017": { + "type": "RSGhost", + "setName": null + } + }, + "topologyType": "Unknown", + "logicalSessionTimeoutMinutes": null, + "setName": null + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_ghost.yml b/test/spec/server-discovery-and-monitoring/rs/discover_ghost.yml new file mode 100644 index 00000000000..9b2ddd6a859 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_ghost.yml @@ -0,0 +1,35 @@ +description: "Discover ghost with directConnection URI option" + +uri: "mongodb://b/?directConnection=false" + +phases: [ + + { + responses: [ + + ["b:27017", { + + ok: 1, + ismaster: false, + isreplicaset: true, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "b:27017": { + + type: "RSGhost", + setName: + } + }, + topologyType: "Unknown", + logicalSessionTimeoutMinutes: null, + setName: + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/ghost_discovered.json b/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.json similarity index 91% rename from test/spec/server-discovery-and-monitoring/rs/ghost_discovered.json rename to test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.json index bf22cbb0eb5..df504b6ca4a 100644 --- a/test/spec/server-discovery-and-monitoring/rs/ghost_discovered.json +++ b/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.json @@ -1,5 +1,5 @@ { - "description": "Ghost discovered", + "description": "Discover ghost with replicaSet URI option", "uri": "mongodb://a,b/?replicaSet=rs", "phases": [ { diff --git a/test/spec/server-discovery-and-monitoring/rs/ghost_discovered.yml b/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.yml similarity index 92% rename from test/spec/server-discovery-and-monitoring/rs/ghost_discovered.yml rename to test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.yml index 97cc92b9ed9..638301e63e7 100644 --- a/test/spec/server-discovery-and-monitoring/rs/ghost_discovered.yml +++ b/test/spec/server-discovery-and-monitoring/rs/discover_ghost_replicaset.yml @@ -1,4 +1,4 @@ -description: "Ghost discovered" +description: "Discover ghost with replicaSet URI option" uri: "mongodb://a,b/?replicaSet=rs" diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_hidden.json b/test/spec/server-discovery-and-monitoring/rs/discover_hidden.json new file mode 100644 index 00000000000..cb68120eafb --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_hidden.json @@ -0,0 +1,45 @@ +{ + "description": "Discover hidden with directConnection URI option", + "uri": "mongodb://a/?directConnection=false", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": false, + "secondary": true, + "hidden": true, + "hosts": [ + "c:27017", + "d:27017" + ], + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSOther", + "setName": "rs" + }, + "c:27017": { + "type": "Unknown", + "setName": null + }, + "d:27017": { + "type": "Unknown", + "setName": null + } + }, + "topologyType": "ReplicaSetNoPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_hidden.yml b/test/spec/server-discovery-and-monitoring/rs/discover_hidden.yml new file mode 100644 index 00000000000..a54069c338b --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_hidden.yml @@ -0,0 +1,50 @@ +description: "Discover hidden with directConnection URI option" + +uri: "mongodb://a/?directConnection=false" + +phases: [ + + { + responses: [ + + ["a:27017", { + + ok: 1, + ismaster: false, + secondary: true, + hidden: true, + hosts: ["c:27017", "d:27017"], + setName: "rs", + minWireVersion: 0, + maxWireVersion: 6 + }], + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "RSOther", + setName: "rs" + }, + + "c:27017": { + + type: "Unknown", + setName: + }, + + "d:27017": { + + type: "Unknown", + setName: + } + }, + topologyType: "ReplicaSetNoPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.json new file mode 100644 index 00000000000..216328dfa5d --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.json @@ -0,0 +1,45 @@ +{ + "description": "Discover hidden with replicaSet URI option", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": false, + "secondary": true, + "hidden": true, + "hosts": [ + "c:27017", + "d:27017" + ], + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSOther", + "setName": "rs" + }, + "c:27017": { + "type": "Unknown", + "setName": null + }, + "d:27017": { + "type": "Unknown", + "setName": null + } + }, + "topologyType": "ReplicaSetNoPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.yml new file mode 100644 index 00000000000..1b6f41b01fc --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_hidden_replicaset.yml @@ -0,0 +1,50 @@ +description: "Discover hidden with replicaSet URI option" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + { + responses: [ + + ["a:27017", { + + ok: 1, + ismaster: false, + secondary: true, + hidden: true, + hosts: ["c:27017", "d:27017"], + setName: "rs", + minWireVersion: 0, + maxWireVersion: 6 + }], + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "RSOther", + setName: "rs" + }, + + "c:27017": { + + type: "Unknown", + setName: + }, + + "d:27017": { + + type: "Unknown", + setName: + } + }, + topologyType: "ReplicaSetNoPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_passives.json b/test/spec/server-discovery-and-monitoring/rs/discover_passives.json index e46249d6686..05922dc51c5 100644 --- a/test/spec/server-discovery-and-monitoring/rs/discover_passives.json +++ b/test/spec/server-discovery-and-monitoring/rs/discover_passives.json @@ -1,6 +1,6 @@ { - "description": "Discover passives", - "uri": "mongodb://a/?replicaSet=rs", + "description": "Discover passives with directConnection URI option", + "uri": "mongodb://a/?directConnection=false", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_passives.yml b/test/spec/server-discovery-and-monitoring/rs/discover_passives.yml index 14ca42e454f..3baed64aa03 100644 --- a/test/spec/server-discovery-and-monitoring/rs/discover_passives.yml +++ b/test/spec/server-discovery-and-monitoring/rs/discover_passives.yml @@ -1,6 +1,6 @@ -description: "Discover passives" +description: "Discover passives with directConnection URI option" -uri: "mongodb://a/?replicaSet=rs" +uri: "mongodb://a/?directConnection=false" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.json new file mode 100644 index 00000000000..f9d8c2e032f --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.json @@ -0,0 +1,78 @@ +{ + "description": "Discover passives with replicaSet URI option", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": true, + "hosts": [ + "a:27017" + ], + "passives": [ + "b:27017" + ], + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + }, + "b:27017": { + "type": "Unknown", + "setName": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + }, + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "ismaster": false, + "secondary": true, + "passive": true, + "hosts": [ + "a:27017" + ], + "passives": [ + "b:27017" + ], + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + }, + "b:27017": { + "type": "RSSecondary", + "setName": "rs" + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.yml new file mode 100644 index 00000000000..6d34516afcc --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_passives_replicaset.yml @@ -0,0 +1,81 @@ +description: "Discover passives with replicaSet URI option" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + { + responses: [ + + ["a:27017", { + + ok: 1, + ismaster: true, + hosts: ["a:27017"], + passives: ["b:27017"], + setName: "rs", + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "RSPrimary", + setName: "rs" + }, + + "b:27017": { + + type: "Unknown", + setName: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + }, + { + responses: [ + + ["b:27017", { + + ok: 1, + ismaster: false, + secondary: true, + passive: true, + hosts: ["a:27017"], + passives: ["b:27017"], + setName: "rs", + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "RSPrimary", + setName: "rs" + }, + + "b:27017": { + + type: "RSSecondary", + setName: "rs" + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_primary.json b/test/spec/server-discovery-and-monitoring/rs/discover_primary.json index ea2cce9b72b..b9032144d46 100644 --- a/test/spec/server-discovery-and-monitoring/rs/discover_primary.json +++ b/test/spec/server-discovery-and-monitoring/rs/discover_primary.json @@ -1,6 +1,6 @@ { - "description": "Replica set discovery from primary", - "uri": "mongodb://a/?replicaSet=rs", + "description": "Discover primary with directConnection URI option", + "uri": "mongodb://a/?directConnection=false", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_primary.yml b/test/spec/server-discovery-and-monitoring/rs/discover_primary.yml index 8eb078d9581..505acfb86f2 100644 --- a/test/spec/server-discovery-and-monitoring/rs/discover_primary.yml +++ b/test/spec/server-discovery-and-monitoring/rs/discover_primary.yml @@ -1,6 +1,6 @@ -description: "Replica set discovery from primary" +description: "Discover primary with directConnection URI option" -uri: "mongodb://a/?replicaSet=rs" +uri: "mongodb://a/?directConnection=false" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.json new file mode 100644 index 00000000000..6f639b1c7e5 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.json @@ -0,0 +1,39 @@ +{ + "description": "Discover primary with replicaSet URI option", + "uri": "mongodb://a/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": true, + "setName": "rs", + "hosts": [ + "a:27017", + "b:27017" + ], + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + }, + "b:27017": { + "type": "Unknown", + "setName": null + } + }, + "topologyType": "ReplicaSetWithPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.yml new file mode 100644 index 00000000000..330ed20b516 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_primary_replicaset.yml @@ -0,0 +1,42 @@ +description: "Discover primary with replicaSet URI option" + +uri: "mongodb://a/?replicaSet=rs" + +phases: [ + + { + responses: [ + + ["a:27017", { + + ok: 1, + ismaster: true, + setName: "rs", + hosts: ["a:27017", "b:27017"], + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "RSPrimary", + setName: "rs" + }, + + "b:27017": { + + type: "Unknown", + setName: + } + }, + topologyType: "ReplicaSetWithPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_rsother.json b/test/spec/server-discovery-and-monitoring/rs/discover_rsother.json new file mode 100644 index 00000000000..2cf5a5a6dbf --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_rsother.json @@ -0,0 +1,44 @@ +{ + "description": "Discover RSOther with directConnection URI option", + "uri": "mongodb://b/?directConnection=false", + "phases": [ + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "ismaster": false, + "secondary": false, + "hosts": [ + "c:27017", + "d:27017" + ], + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "b:27017": { + "type": "RSOther", + "setName": "rs" + }, + "c:27017": { + "type": "Unknown", + "setName": null + }, + "d:27017": { + "type": "Unknown", + "setName": null + } + }, + "topologyType": "ReplicaSetNoPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_rsother.yml b/test/spec/server-discovery-and-monitoring/rs/discover_rsother.yml new file mode 100644 index 00000000000..1f06c78566e --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_rsother.yml @@ -0,0 +1,49 @@ +description: "Discover RSOther with directConnection URI option" + +uri: "mongodb://b/?directConnection=false" + +phases: [ + + { + responses: [ + + ["b:27017", { + + ok: 1, + ismaster: false, + secondary: false, + hosts: ["c:27017", "d:27017"], + setName: "rs", + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "b:27017": { + + type: "RSOther", + setName: "rs" + }, + + "c:27017": { + + type: "Unknown", + setName: + }, + + "d:27017": { + + type: "Unknown", + setName: + } + }, + topologyType: "ReplicaSetNoPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/rsother_discovered.json b/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.json similarity index 95% rename from test/spec/server-discovery-and-monitoring/rs/rsother_discovered.json rename to test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.json index c575501d803..d9420ca5295 100644 --- a/test/spec/server-discovery-and-monitoring/rs/rsother_discovered.json +++ b/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.json @@ -1,5 +1,5 @@ { - "description": "RSOther discovered", + "description": "Discover RSOther with replicaSet URI option", "uri": "mongodb://a,b/?replicaSet=rs", "phases": [ { diff --git a/test/spec/server-discovery-and-monitoring/rs/rsother_discovered.yml b/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.yml similarity index 96% rename from test/spec/server-discovery-and-monitoring/rs/rsother_discovered.yml rename to test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.yml index b84cd00986b..24f4e302be3 100644 --- a/test/spec/server-discovery-and-monitoring/rs/rsother_discovered.yml +++ b/test/spec/server-discovery-and-monitoring/rs/discover_rsother_replicaset.yml @@ -1,4 +1,4 @@ -description: "RSOther discovered" +description: "Discover RSOther with replicaSet URI option" uri: "mongodb://a,b/?replicaSet=rs" diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_secondary.json b/test/spec/server-discovery-and-monitoring/rs/discover_secondary.json index 7210b3845c7..02123625a70 100644 --- a/test/spec/server-discovery-and-monitoring/rs/discover_secondary.json +++ b/test/spec/server-discovery-and-monitoring/rs/discover_secondary.json @@ -1,6 +1,6 @@ { - "description": "Replica set discovery from secondary", - "uri": "mongodb://b/?replicaSet=rs", + "description": "Discover secondary with directConnection URI option", + "uri": "mongodb://b/?directConnection=false", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_secondary.yml b/test/spec/server-discovery-and-monitoring/rs/discover_secondary.yml index 221e3693bd9..3fdbccb283b 100644 --- a/test/spec/server-discovery-and-monitoring/rs/discover_secondary.yml +++ b/test/spec/server-discovery-and-monitoring/rs/discover_secondary.yml @@ -1,6 +1,6 @@ -description: "Replica set discovery from secondary" +description: "Discover secondary with directConnection URI option" -uri: "mongodb://b/?replicaSet=rs" +uri: "mongodb://b/?directConnection=false" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.json b/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.json new file mode 100644 index 00000000000..3dde3166b41 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.json @@ -0,0 +1,40 @@ +{ + "description": "Discover secondary with replicaSet URI option", + "uri": "mongodb://b/?replicaSet=rs", + "phases": [ + { + "responses": [ + [ + "b:27017", + { + "ok": 1, + "ismaster": false, + "secondary": true, + "setName": "rs", + "hosts": [ + "a:27017", + "b:27017" + ], + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null + }, + "b:27017": { + "type": "RSSecondary", + "setName": "rs" + } + }, + "topologyType": "ReplicaSetNoPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.yml b/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.yml new file mode 100644 index 00000000000..3781d0e42d3 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/discover_secondary_replicaset.yml @@ -0,0 +1,43 @@ +description: "Discover secondary with replicaSet URI option" + +uri: "mongodb://b/?replicaSet=rs" + +phases: [ + + { + responses: [ + + ["b:27017", { + + ok: 1, + ismaster: false, + secondary: true, + setName: "rs", + hosts: ["a:27017", "b:27017"], + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "Unknown", + setName: + }, + + "b:27017": { + + type: "RSSecondary", + setName: "rs" + } + }, + topologyType: "ReplicaSetNoPrimary", + logicalSessionTimeoutMinutes: null, + setName: "rs" + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.yml b/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.yml index f7a3cdad0e2..e41dbcd6fe0 100644 --- a/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.yml +++ b/test/spec/server-discovery-and-monitoring/rs/incompatible_arbiter.yml @@ -1,5 +1,7 @@ description: "Incompatible arbiter" + uri: "mongodb://a,b/?replicaSet=rs" + phases: - responses: - diff --git a/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.yml b/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.yml index e04487cb7d0..fa73ec3ddd9 100644 --- a/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.yml +++ b/test/spec/server-discovery-and-monitoring/rs/incompatible_ghost.yml @@ -1,5 +1,7 @@ description: "Incompatible ghost" + uri: "mongodb://a,b/?replicaSet=rs" + phases: - responses: - diff --git a/test/spec/server-discovery-and-monitoring/rs/incompatible_other.yml b/test/spec/server-discovery-and-monitoring/rs/incompatible_other.yml index 9ee452daf93..848b307ab06 100644 --- a/test/spec/server-discovery-and-monitoring/rs/incompatible_other.yml +++ b/test/spec/server-discovery-and-monitoring/rs/incompatible_other.yml @@ -1,5 +1,7 @@ description: "Incompatible other" + uri: "mongodb://a,b/?replicaSet=rs" + phases: - responses: - diff --git a/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.json b/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.json new file mode 100644 index 00000000000..a0f69de486e --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.json @@ -0,0 +1,25 @@ +{ + "description": "replicaSet URI option causes starting topology to be RSNP", + "uri": "mongodb://a/?replicaSet=rs&directConnection=false", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": true, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": {}, + "topologyType": "ReplicaSetNoPrimary", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.yml b/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.yml new file mode 100644 index 00000000000..cb15fac812d --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/rs/replicaset_rsnp.yml @@ -0,0 +1,20 @@ +description: replicaSet URI option causes starting topology to be RSNP + +uri: "mongodb://a/?replicaSet=rs&directConnection=false" + +phases: + # We are connecting to a standalone + - responses: + - + - "a:27017" + - ok: 1 + ismaster: true + minWireVersion: 0 + maxWireVersion: 6 + outcome: + # Server is removed because it's a standalone and the driver + # started in RSNP topology + servers: {} + topologyType: "ReplicaSetNoPrimary" + logicalSessionTimeoutMinutes: ~ + setName: "rs" diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.json b/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.json index d2a70f67889..769e272a668 100644 --- a/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.json +++ b/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.json @@ -1,5 +1,6 @@ { "description": "Secondary mismatched me", + "uri": "mongodb://localhost:27017/?replicaSet=rs", "phases": [ { "outcome": { @@ -35,6 +36,5 @@ ] ] } - ], - "uri": "mongodb://localhost:27017/?replicaSet=rs" + ] } diff --git a/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.yml b/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.yml index 7a093c8dccd..be2ace0cf0f 100644 --- a/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.yml +++ b/test/spec/server-discovery-and-monitoring/rs/secondary_mismatched_me.yml @@ -1,4 +1,7 @@ description: Secondary mismatched me + +uri: 'mongodb://localhost:27017/?replicaSet=rs' + phases: - outcome: servers: @@ -22,5 +25,3 @@ phases: setName: rs minWireVersion: 0 maxWireVersion: 6 -uri: 'mongodb://localhost:27017/?replicaSet=rs' - diff --git a/test/spec/server-discovery-and-monitoring/rs/too_new.yml b/test/spec/server-discovery-and-monitoring/rs/too_new.yml index a47527af4f1..5f185f7a198 100644 --- a/test/spec/server-discovery-and-monitoring/rs/too_new.yml +++ b/test/spec/server-discovery-and-monitoring/rs/too_new.yml @@ -1,5 +1,7 @@ description: "Replica set member with large minWireVersion" + uri: "mongodb://a,b/?replicaSet=rs" + phases: [ { responses: [ diff --git a/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.json b/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.json new file mode 100644 index 00000000000..427889f8cc2 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.json @@ -0,0 +1,30 @@ +{ + "description": "Discover single mongos", + "uri": "mongodb://a/?directConnection=false", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": true, + "msg": "isdbgrid", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Mongos", + "setName": null + } + }, + "topologyType": "Sharded", + "setName": null + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.yml b/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.yml new file mode 100644 index 00000000000..be12100925e --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/sharded/discover_single_mongos.yml @@ -0,0 +1,23 @@ +description: "Discover single mongos" + +uri: "mongodb://a/?directConnection=false" + +phases: + + - responses: + - + - "a:27017" + - + ok: 1 + ismaster: true + msg: "isdbgrid" + minWireVersion: 0 + maxWireVersion: 6 + + outcome: + servers: + "a:27017": + type: "Mongos" + setName: + topologyType: "Sharded" + setName: diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.json index 44581501862..afd5edc1d21 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.json +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.json @@ -1,6 +1,6 @@ { "description": "Direct connection to RSPrimary via external IP", - "uri": "mongodb://a", + "uri": "mongodb://a/?directConnection=true", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.yml index bf9b68aeb73..1b3a8db70bc 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.yml +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_external_ip.yml @@ -1,6 +1,6 @@ description: "Direct connection to RSPrimary via external IP" -uri: "mongodb://a" +uri: "mongodb://a/?directConnection=true" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.json index a7fa0794901..9175049cc64 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.json +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.json @@ -1,6 +1,6 @@ { - "description": "Connect to mongos", - "uri": "mongodb://a", + "description": "Direct connection to mongos", + "uri": "mongodb://a/?directConnection=true", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.yml index e0397230198..1253bbcc8d4 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.yml +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_mongos.yml @@ -1,6 +1,6 @@ -description: "Connect to mongos" +description: "Direct connection to mongos" -uri: "mongodb://a" +uri: "mongodb://a/?directConnection=true" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.json new file mode 100644 index 00000000000..c629a709bee --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.json @@ -0,0 +1,31 @@ +{ + "description": "Direct connection with replicaSet URI option", + "uri": "mongodb://a/?replicaSet=rs&directConnection=true", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": true, + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + } + }, + "topologyType": "Single", + "logicalSessionTimeoutMinutes": null, + "setName": "rs" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.yml new file mode 100644 index 00000000000..25418e66e1a --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_replicaset.yml @@ -0,0 +1,22 @@ +description: Direct connection with replicaSet URI option + +uri: "mongodb://a/?replicaSet=rs&directConnection=true" + +phases: + # We are connecting to a replica set member + - responses: + - + - "a:27017" + - ok: 1 + ismaster: true + setName: rs + minWireVersion: 0 + maxWireVersion: 6 + outcome: + servers: + "a:27017": + type: "RSPrimary" + setName: "rs" + topologyType: "Single" + logicalSessionTimeoutMinutes: + setName: rs diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.json index 3ef374d6f1e..b07beb31ed2 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.json +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.json @@ -1,6 +1,6 @@ { - "description": "Connect to RSArbiter", - "uri": "mongodb://a", + "description": "Direct connection to RSArbiter", + "uri": "mongodb://a/?directConnection=true", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.yml index 4d03d0baabd..c531aab5e51 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.yml +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsarbiter.yml @@ -1,6 +1,6 @@ -description: "Connect to RSArbiter" +description: "Direct connection to RSArbiter" -uri: "mongodb://a" +uri: "mongodb://a/?directConnection=true" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.json index bd5aaf7f044..7216a13345e 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.json +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.json @@ -1,6 +1,6 @@ { - "description": "Connect to RSPrimary", - "uri": "mongodb://a", + "description": "Direct connection to RSPrimary", + "uri": "mongodb://a/?directConnection=true", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.yml index c4b2fa0b3a5..0aea56e12b7 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.yml +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rsprimary.yml @@ -1,6 +1,6 @@ -description: "Connect to RSPrimary" +description: "Direct connection to RSPrimary" -uri: "mongodb://a" +uri: "mongodb://a/?directConnection=true" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.json index 3b4f3c8c5ad..573036f2aae 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.json +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.json @@ -1,6 +1,6 @@ { - "description": "Connect to RSSecondary", - "uri": "mongodb://a", + "description": "Direct connection to RSSecondary", + "uri": "mongodb://a/?directConnection=true", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.yml index a57332f253d..6cd3e5909a0 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.yml +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_rssecondary.yml @@ -1,6 +1,6 @@ -description: "Connect to RSSecondary" +description: "Direct connection to RSSecondary" -uri: "mongodb://a" +uri: "mongodb://a/?directConnection=true" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.json index a40debd1838..720ec3dd82d 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.json +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.json @@ -1,6 +1,6 @@ { "description": "Direct connection to slave", - "uri": "mongodb://a", + "uri": "mongodb://a/?directConnection=true", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.yml index 166470cae50..7c2436db165 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.yml +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_slave.yml @@ -1,6 +1,6 @@ description: "Direct connection to slave" -uri: "mongodb://a" +uri: "mongodb://a/?directConnection=true" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.json index 2ecff9b9ae2..c53d76e76e5 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.json +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.json @@ -1,6 +1,6 @@ { - "description": "Connect to standalone", - "uri": "mongodb://a", + "description": "Direct connection to standalone", + "uri": "mongodb://a/?directConnection=true", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.yml index 8c5bcdef44a..7ad5f590b85 100644 --- a/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.yml +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_standalone.yml @@ -1,6 +1,6 @@ -description: "Connect to standalone" +description: "Direct connection to standalone" -uri: "mongodb://a" +uri: "mongodb://a/?directConnection=true" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/single/unavailable_seed.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_unavailable_seed.json similarity index 78% rename from test/spec/server-discovery-and-monitoring/single/unavailable_seed.json rename to test/spec/server-discovery-and-monitoring/single/direct_connection_unavailable_seed.json index e9cce02ebfd..16f2735da54 100644 --- a/test/spec/server-discovery-and-monitoring/single/unavailable_seed.json +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_unavailable_seed.json @@ -1,6 +1,6 @@ { - "description": "Unavailable seed", - "uri": "mongodb://a", + "description": "Direct connection to unavailable seed", + "uri": "mongodb://a/?directConnection=true", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/single/unavailable_seed.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_unavailable_seed.yml similarity index 80% rename from test/spec/server-discovery-and-monitoring/single/unavailable_seed.yml rename to test/spec/server-discovery-and-monitoring/single/direct_connection_unavailable_seed.yml index c4cfbf76ccb..46284ded6d6 100644 --- a/test/spec/server-discovery-and-monitoring/single/unavailable_seed.yml +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_unavailable_seed.yml @@ -1,6 +1,6 @@ -description: "Unavailable seed" +description: "Direct connection to unavailable seed" -uri: "mongodb://a" +uri: "mongodb://a/?directConnection=true" phases: [ diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.json b/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.json new file mode 100644 index 00000000000..8cfbd6e28c0 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.json @@ -0,0 +1,35 @@ +{ + "description": "Direct connection to RSPrimary with wrong set name", + "uri": "mongodb://a/?directConnection=true&replicaSet=wrong", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": true, + "hosts": [ + "a:27017", + "b:27017" + ], + "setName": "rs", + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "RSPrimary", + "setName": "rs" + } + }, + "topologyType": "Single", + "logicalSessionTimeoutMinutes": null, + "setName": "wrong" + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.yml b/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.yml new file mode 100644 index 00000000000..8a94d95ebe0 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/single/direct_connection_wrong_set_name.yml @@ -0,0 +1,36 @@ +description: "Direct connection to RSPrimary with wrong set name" + +uri: "mongodb://a/?directConnection=true&replicaSet=wrong" + +phases: [ + + { + responses: [ + + ["a:27017", { + + ok: 1, + ismaster: true, + hosts: ["a:27017", "b:27017"], + setName: "rs", + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "RSPrimary", + setName: "rs" + } + }, + topologyType: "Single", + logicalSessionTimeoutMinutes: null, + setName: wrong + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/single/discover_standalone.json b/test/spec/server-discovery-and-monitoring/single/discover_standalone.json new file mode 100644 index 00000000000..eb6c6ae7469 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/single/discover_standalone.json @@ -0,0 +1,30 @@ +{ + "description": "Discover standalone", + "uri": "mongodb://a/?directConnection=false", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": true, + "minWireVersion": 0, + "maxWireVersion": 6 + } + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Standalone", + "setName": null + } + }, + "topologyType": "Single", + "logicalSessionTimeoutMinutes": null, + "setName": null + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/single/discover_standalone.yml b/test/spec/server-discovery-and-monitoring/single/discover_standalone.yml new file mode 100644 index 00000000000..5071033b8ea --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/single/discover_standalone.yml @@ -0,0 +1,34 @@ +description: "Discover standalone" + +uri: "mongodb://a/?directConnection=false" + +phases: [ + + { + responses: [ + + ["a:27017", { + + ok: 1, + ismaster: true, + minWireVersion: 0, + maxWireVersion: 6 + }] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "Standalone", + setName: + } + }, + topologyType: "Single", + logicalSessionTimeoutMinutes: null, + setName: + } + } +] diff --git a/test/spec/server-discovery-and-monitoring/single/discover_unavailable_seed.json b/test/spec/server-discovery-and-monitoring/single/discover_unavailable_seed.json new file mode 100644 index 00000000000..b1f306c2be6 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/single/discover_unavailable_seed.json @@ -0,0 +1,25 @@ +{ + "description": "Discover unavailable seed", + "uri": "mongodb://a/?directConnection=false", + "phases": [ + { + "responses": [ + [ + "a:27017", + {} + ] + ], + "outcome": { + "servers": { + "a:27017": { + "type": "Unknown", + "setName": null + } + }, + "topologyType": "Unknown", + "logicalSessionTimeoutMinutes": null, + "setName": null + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/single/discover_unavailable_seed.yml b/test/spec/server-discovery-and-monitoring/single/discover_unavailable_seed.yml new file mode 100644 index 00000000000..e451025e8a1 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/single/discover_unavailable_seed.yml @@ -0,0 +1,28 @@ +description: "Discover unavailable seed" + +uri: "mongodb://a/?directConnection=false" + +phases: [ + + { + responses: [ + + ["a:27017", {}] + ], + + outcome: { + + servers: { + + "a:27017": { + + type: "Unknown", + setName: + } + }, + topologyType: "Unknown", + logicalSessionTimeoutMinutes: null, + setName: + } + } +] diff --git a/test/spec/uri-options/concern-options.json b/test/spec/uri-options/concern-options.json index 2b3783746c3..5a8ef6c272b 100644 --- a/test/spec/uri-options/concern-options.json +++ b/test/spec/uri-options/concern-options.json @@ -36,15 +36,6 @@ "w": "arbitraryButStillValid" } }, - { - "description": "Too low w causes a warning", - "uri": "mongodb://example.com/?w=-2", - "valid": true, - "warning": true, - "hosts": null, - "auth": null, - "options": {} - }, { "description": "Non-numeric wTimeoutMS causes a warning", "uri": "mongodb://example.com/?wTimeoutMS=invalid", diff --git a/test/spec/uri-options/connection-options.json b/test/spec/uri-options/connection-options.json index 1e2dccd6e29..1cd7c55f08b 100644 --- a/test/spec/uri-options/connection-options.json +++ b/test/spec/uri-options/connection-options.json @@ -117,6 +117,56 @@ "hosts": null, "auth": null, "options": {} + }, + { + "description": "directConnection=true", + "uri": "mongodb://example.com/?directConnection=true", + "valid": true, + "warning": false, + "hosts": null, + "auth": null, + "options": { + "directConnection": true + } + }, + { + "description": "directConnection=true with multiple seeds", + "uri": "mongodb://example1.com,example2.com/?directConnection=true", + "valid": false, + "warning": false, + "hosts": null, + "auth": null + }, + { + "description": "directConnection=false", + "uri": "mongodb://example.com/?directConnection=false", + "valid": true, + "warning": false, + "hosts": null, + "auth": null, + "options": { + "directConnection": false + } + }, + { + "description": "directConnection=false with multiple seeds", + "uri": "mongodb://example1.com,example2.com/?directConnection=false", + "valid": true, + "warning": false, + "hosts": null, + "auth": null, + "options": { + "directConnection": false + } + }, + { + "description": "Invalid directConnection value", + "uri": "mongodb://example.com/?directConnection=invalid", + "valid": true, + "warning": true, + "hosts": null, + "auth": null, + "options": {} } ] } diff --git a/test/spec/uri-options/connection-options.yml b/test/spec/uri-options/connection-options.yml index a637dae2981..c90b88d743b 100644 --- a/test/spec/uri-options/connection-options.yml +++ b/test/spec/uri-options/connection-options.yml @@ -104,3 +104,46 @@ tests: hosts: ~ auth: ~ options: {} + + - + description: directConnection=true + uri: "mongodb://example.com/?directConnection=true" + valid: true + warning: false + hosts: ~ + auth: ~ + options: + directConnection: true + - + description: directConnection=true with multiple seeds + uri: "mongodb://example1.com,example2.com/?directConnection=true" + valid: false + warning: false + hosts: ~ + auth: ~ + - + description: directConnection=false + uri: "mongodb://example.com/?directConnection=false" + valid: true + warning: false + hosts: ~ + auth: ~ + options: + directConnection: false + - + description: directConnection=false with multiple seeds + uri: "mongodb://example1.com,example2.com/?directConnection=false" + valid: true + warning: false + hosts: ~ + auth: ~ + options: + directConnection: false + - + description: Invalid directConnection value + uri: "mongodb://example.com/?directConnection=invalid" + valid: true + warning: true + hosts: ~ + auth: ~ + options: {} diff --git a/test/unit/core/mongodb_srv.test.js b/test/unit/core/mongodb_srv.test.js index 6d45fd554c9..f4a03b0171e 100644 --- a/test/unit/core/mongodb_srv.test.js +++ b/test/unit/core/mongodb_srv.test.js @@ -29,26 +29,18 @@ describe('mongodb+srv', function() { it(test[1].comment, { metadata: { requires: { topology: ['single'] } }, test: function(done) { - parseConnectionString(test[1].uri, { caseTranslate: false }, (err, result) => { + parseConnectionString(test[1].uri, (err, result) => { if (test[1].error) { expect(err).to.exist; expect(result).to.not.exist; } else { expect(err).to.not.exist; expect(result).to.exist; - - if (test[1].options && test[1].options.replicaSet) { - expect(result.options.replicaset).to.equal(test[1].options.replicaSet); - } - - if (test[1].options && test[1].options.ssl) { - expect(result.options.ssl).to.equal(test[1].options.ssl); + if (test[1].options) { + expect(result) + .property('options') + .to.matchMongoSpec(test[1].options); } - - if (test[1].options && test[1].options.authSource) { - expect(result.options.authsource).to.equal(test[1].options.authSource); - } - if ( test[1].parsed_options && test[1].parsed_options.user && @@ -58,7 +50,6 @@ describe('mongodb+srv', function() { expect(result.auth.password).to.equal(test[1].parsed_options.password); } } - done(); }); } diff --git a/test/unit/sdam/spec.test.js b/test/unit/sdam/spec.test.js index fbf619c5537..64f036320a1 100644 --- a/test/unit/sdam/spec.test.js +++ b/test/unit/sdam/spec.test.js @@ -51,11 +51,22 @@ describe('Server Discovery and Monitoring (spec)', function() { serverConnect.restore(); }); + // DRIVERS-1249 should add directConnection and then update spec, remove skip + const shouldSkip = desc => { + const descriptions = [ + 'Monitoring a standalone connection', + 'Monitoring a standalone connection - suppress update events for equal server descriptions' + ]; + return descriptions.includes(desc); + }; + const specTests = collectTests(); Object.keys(specTests).forEach(specTestName => { describe(specTestName, () => { specTests[specTestName].forEach(testData => { - it(testData.description, { + const skip = shouldSkip(testData.description); + const type = skip ? it.skip : it; + type(testData.description, { metadata: { requires: { topology: 'single' } }, test: function(done) { executeSDAMTest(testData, done);