diff --git a/lib/core/uri_parser.js b/lib/core/uri_parser.js index 90763ec8365..eac9bc92b04 100644 --- a/lib/core/uri_parser.js +++ b/lib/core/uri_parser.js @@ -687,15 +687,6 @@ function parseConnectionString(uri, options, callback) { return callback(new MongoParseError('directConnection option requires exactly one host')); } - // NOTE: this behavior will go away in v4.0, we will always auto discover there - if ( - parsedOptions.directConnection == null && - hosts.length === 1 && - parsedOptions.replicaSet == null - ) { - parsedOptions.directConnection = true; - } - const result = { hosts: hosts, auth: auth.db || auth.username ? auth : null, diff --git a/test/functional/sharding_connection.test.js b/test/functional/sharding_connection.test.js index fc4acfe7c33..8d3b5ed5d8f 100644 --- a/test/functional/sharding_connection.test.js +++ b/test/functional/sharding_connection.test.js @@ -1,13 +1,29 @@ 'use strict'; +const withClient = require('./shared').withClient; const setupDatabase = require('./shared').setupDatabase; const expect = require('chai').expect; +const TopologyType = require('../../lib/core/sdam/common').TopologyType; describe('Sharding (Connection)', function() { before(function() { return setupDatabase(this.configuration); }); + it('Should use sharded topology', { + metadata: { requires: { topology: 'sharded' } }, + test: function() { + const client = this.configuration.newClient({}, { useUnifiedTopology: true }); + return withClient(client, (client, done) => { + expect(client).to.exist; + expect(client) + .nested.property('topology.description.type') + .to.equal(TopologyType.Sharded); + return done(); + })(); + } + }); + /** * @ignore */ diff --git a/test/spec/server-discovery-and-monitoring/integration/isMaster-command-error.yml b/test/spec/server-discovery-and-monitoring/integration/isMaster-command-error.yml index 192f079bc26..e7b051669bb 100644 --- a/test/spec/server-discovery-and-monitoring/integration/isMaster-command-error.yml +++ b/test/spec/server-discovery-and-monitoring/integration/isMaster-command-error.yml @@ -27,7 +27,7 @@ tests: appname: commandErrorHandshakeTest operations: # The command error on the initial handshake should mark the server - # Unknown and clear the pool. + # Unknown (emitting a ServerDescriptionChangedEvent) and clear the pool. - name: waitForEvent object: testRunner arguments: diff --git a/test/spec/server-discovery-and-monitoring/integration/isMaster-network-error.yml b/test/spec/server-discovery-and-monitoring/integration/isMaster-network-error.yml index 0a0d4dd5f37..f213b81435b 100644 --- a/test/spec/server-discovery-and-monitoring/integration/isMaster-network-error.yml +++ b/test/spec/server-discovery-and-monitoring/integration/isMaster-network-error.yml @@ -26,7 +26,7 @@ tests: appname: networkErrorHandshakeTest operations: # The network error on the initial handshake should mark the server - # Unknown and clear the pool. + # Unknown (emitting a ServerDescriptionChangedEvent) and clear the pool. - name: waitForEvent object: testRunner arguments: diff --git a/test/spec/server-discovery-and-monitoring/integration/isMaster-timeout.yml b/test/spec/server-discovery-and-monitoring/integration/isMaster-timeout.yml index 269b681be34..4dd8d1a3dee 100644 --- a/test/spec/server-discovery-and-monitoring/integration/isMaster-timeout.yml +++ b/test/spec/server-discovery-and-monitoring/integration/isMaster-timeout.yml @@ -27,7 +27,7 @@ tests: appname: timeoutMonitorHandshakeTest operations: # The network error on the initial handshake should mark the server - # Unknown and clear the pool. + # Unknown (emitting a ServerDescriptionChangedEvent) and clear the pool. - name: waitForEvent object: testRunner arguments: @@ -101,6 +101,9 @@ tests: failCommands: ["isMaster"] appName: timeoutMonitorCheckTest blockConnection: true + # blockTimeMS is evaluated after the waiting for heartbeatFrequencyMS server-side, so this value only + # needs to be greater than connectTimeoutMS. The driver will wait for (500+750)ms and the server will + # respond after (500+1000)ms. blockTimeMS: 1000 # The network error on the next check should mark the server Unknown and # clear the pool. diff --git a/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.json b/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.json new file mode 100644 index 00000000000..c3ab59834ff --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.json @@ -0,0 +1,104 @@ +{ + "description": "Monitoring a discovered standalone connection", + "uri": "mongodb://a:27017/?directConnection=false", + "phases": [ + { + "responses": [ + [ + "a:27017", + { + "ok": 1, + "ismaster": true, + "minWireVersion": 0, + "maxWireVersion": 4 + } + ] + ], + "outcome": { + "events": [ + { + "topology_opening_event": { + "topologyId": "42" + } + }, + { + "topology_description_changed_event": { + "topologyId": "42", + "previousDescription": { + "topologyType": "Unknown", + "servers": [] + }, + "newDescription": { + "topologyType": "Unknown", + "servers": [ + { + "address": "a:27017", + "arbiters": [], + "hosts": [], + "passives": [], + "type": "Unknown" + } + ] + } + } + }, + { + "server_opening_event": { + "topologyId": "42", + "address": "a:27017" + } + }, + { + "server_description_changed_event": { + "topologyId": "42", + "address": "a:27017", + "previousDescription": { + "address": "a:27017", + "arbiters": [], + "hosts": [], + "passives": [], + "type": "Unknown" + }, + "newDescription": { + "address": "a:27017", + "arbiters": [], + "hosts": [], + "passives": [], + "type": "Standalone" + } + } + }, + { + "topology_description_changed_event": { + "topologyId": "42", + "previousDescription": { + "topologyType": "Unknown", + "servers": [ + { + "address": "a:27017", + "arbiters": [], + "hosts": [], + "passives": [], + "type": "Unknown" + } + ] + }, + "newDescription": { + "topologyType": "Single", + "servers": [ + { + "address": "a:27017", + "arbiters": [], + "hosts": [], + "passives": [], + "type": "Standalone" + } + ] + } + } + } + ] + } + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.yml b/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.yml new file mode 100644 index 00000000000..ad4ab14c31f --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.yml @@ -0,0 +1,70 @@ +description: "Monitoring a discovered standalone connection" +uri: "mongodb://a:27017/?directConnection=false" +phases: + - + responses: + - + - "a:27017" + - { ok: 1, ismaster: true, minWireVersion: 0, maxWireVersion: 4 } + + outcome: + events: + - + topology_opening_event: + topologyId: "42" + - + topology_description_changed_event: + topologyId: "42" + previousDescription: + topologyType: "Unknown" + servers: [] + newDescription: + topologyType: "Unknown" + servers: + - + address: "a:27017" + arbiters: [] + hosts: [] + passives: [] + type: "Unknown" + - + server_opening_event: + topologyId: "42" + address: "a:27017" + - + server_description_changed_event: + topologyId: "42" + address: "a:27017" + previousDescription: + address: "a:27017" + arbiters: [] + hosts: [] + passives: [] + type: "Unknown" + newDescription: + address: "a:27017" + arbiters: [] + hosts: [] + passives: [] + type: "Standalone" + - + topology_description_changed_event: + topologyId: "42" + previousDescription: + topologyType: "Unknown" + servers: + - + address: "a:27017" + arbiters: [] + hosts: [] + passives: [] + type: "Unknown" + newDescription: + topologyType: "Single" + servers: + - + address: "a:27017" + arbiters: [] + hosts: [] + passives: [] + type: "Standalone" diff --git a/test/spec/server-discovery-and-monitoring/monitoring/standalone.json b/test/spec/server-discovery-and-monitoring/monitoring/standalone.json index 5d40286c973..3ff10f820fc 100644 --- a/test/spec/server-discovery-and-monitoring/monitoring/standalone.json +++ b/test/spec/server-discovery-and-monitoring/monitoring/standalone.json @@ -1,6 +1,6 @@ { - "description": "Monitoring a standalone connection", - "uri": "mongodb://a:27017", + "description": "Monitoring a direct connection", + "uri": "mongodb://a:27017/?directConnection=true", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/monitoring/standalone.yml b/test/spec/server-discovery-and-monitoring/monitoring/standalone.yml index aff3f7322c8..8787edce341 100644 --- a/test/spec/server-discovery-and-monitoring/monitoring/standalone.yml +++ b/test/spec/server-discovery-and-monitoring/monitoring/standalone.yml @@ -1,5 +1,5 @@ -description: "Monitoring a standalone connection" -uri: "mongodb://a:27017" +description: "Monitoring a direct connection" +uri: "mongodb://a:27017/?directConnection=true" phases: - responses: diff --git a/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.json b/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.json index a4b2d10da80..ceab1449cc7 100644 --- a/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.json +++ b/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.json @@ -1,6 +1,6 @@ { - "description": "Monitoring a standalone connection - suppress update events for equal server descriptions", - "uri": "mongodb://a:27017", + "description": "Monitoring a direct connection - suppress update events for equal server descriptions", + "uri": "mongodb://a:27017/?directConnection=true", "phases": [ { "responses": [ diff --git a/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.yml b/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.yml index 0cffa8fc792..229f8d7c69d 100644 --- a/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.yml +++ b/test/spec/server-discovery-and-monitoring/monitoring/standalone_suppress_equal_description_changes.yml @@ -1,5 +1,5 @@ -description: "Monitoring a standalone connection - suppress update events for equal server descriptions" -uri: "mongodb://a:27017" +description: "Monitoring a direct connection - suppress update events for equal server descriptions" +uri: "mongodb://a:27017/?directConnection=true" phases: - responses: diff --git a/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.json b/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.json index 2c80fa2a974..afa8108ea20 100644 --- a/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.json +++ b/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.json @@ -157,8 +157,7 @@ ], "setName": "rs", "minWireVersion": 0, - "maxWireVersion": 9, - "topologyVersion": null + "maxWireVersion": 9 } ] ], diff --git a/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.yml b/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.yml index d3e7bf6321a..4edf99ba8cb 100644 --- a/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.yml +++ b/test/spec/server-discovery-and-monitoring/rs/topology_version_greater.yml @@ -107,8 +107,7 @@ phases: [ hosts: ["a:27017", "d:27017"], setName: "rs", minWireVersion: 0, - maxWireVersion: 9, - topologyVersion: null + maxWireVersion: 9 }] ],