From 50d6bd105ea887202f185c8fe706ac747a761baf Mon Sep 17 00:00:00 2001 From: Thomas Reggi Date: Wed, 7 Oct 2020 17:43:42 -0400 Subject: [PATCH 1/5] testing sharded topology --- lib/core/uri_parser.js | 9 --------- test/functional/sharding_connection.test.js | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) 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..2cd762cdc20 100644 --- a/test/functional/sharding_connection.test.js +++ b/test/functional/sharding_connection.test.js @@ -1,13 +1,30 @@ '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.only('Should use sharded topology', { + metadata: { requires: { topology: 'sharded' } }, + test: function() { + const client = this.configuration.newClient({}, { useUnifiedTopology: true }); + expect(client.s.options).to.have.property('useUnifiedTopology', true); + return withClient(client, (client, done) => { + expect(client).to.exist; + expect(client.topology).to.exist; + expect(client.topology.description).to.exist; + expect(client.topology.description).to.have.property('type', TopologyType.Sharded); + return done(); + })(); + } + }); + /** * @ignore */ From a134a4310a1f9e98e84670a6bbfc1288da69afc5 Mon Sep 17 00:00:00 2001 From: Thomas Reggi Date: Thu, 8 Oct 2020 09:48:33 -0400 Subject: [PATCH 2/5] Update test/functional/sharding_connection.test.js Co-authored-by: Eric Adum --- test/functional/sharding_connection.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/sharding_connection.test.js b/test/functional/sharding_connection.test.js index 2cd762cdc20..45c18c8b74d 100644 --- a/test/functional/sharding_connection.test.js +++ b/test/functional/sharding_connection.test.js @@ -10,7 +10,7 @@ describe('Sharding (Connection)', function() { return setupDatabase(this.configuration); }); - it.only('Should use sharded topology', { + it('Should use sharded topology', { metadata: { requires: { topology: 'sharded' } }, test: function() { const client = this.configuration.newClient({}, { useUnifiedTopology: true }); From 1029e958bf3364ca2902a62a1f4d6cdf5fe1de35 Mon Sep 17 00:00:00 2001 From: Thomas Reggi Date: Fri, 9 Oct 2020 18:17:24 -0400 Subject: [PATCH 3/5] update sdam tests --- .../integration/isMaster-command-error.yml | 2 +- .../integration/isMaster-network-error.yml | 2 +- .../integration/isMaster-timeout.yml | 5 +- .../monitoring/discovered_standalone.json | 104 ++++++++++++++++++ .../monitoring/discovered_standalone.yml | 70 ++++++++++++ .../monitoring/standalone.json | 4 +- .../monitoring/standalone.yml | 4 +- ...ne_suppress_equal_description_changes.json | 4 +- ...one_suppress_equal_description_changes.yml | 4 +- .../rs/topology_version_greater.json | 3 +- .../rs/topology_version_greater.yml | 3 +- 11 files changed, 190 insertions(+), 15 deletions(-) create mode 100644 test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.json create mode 100644 test/spec/server-discovery-and-monitoring/monitoring/discovered_standalone.yml 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 }] ], From 1de0832ba24f469715b15d1cce1c5316bf00bf0b Mon Sep 17 00:00:00 2001 From: Thomas Reggi Date: Mon, 12 Oct 2020 10:26:07 -0400 Subject: [PATCH 4/5] Update test/functional/sharding_connection.test.js Co-authored-by: Matt Broadstone --- test/functional/sharding_connection.test.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/functional/sharding_connection.test.js b/test/functional/sharding_connection.test.js index 45c18c8b74d..dcbbc5bd280 100644 --- a/test/functional/sharding_connection.test.js +++ b/test/functional/sharding_connection.test.js @@ -17,9 +17,7 @@ describe('Sharding (Connection)', function() { expect(client.s.options).to.have.property('useUnifiedTopology', true); return withClient(client, (client, done) => { expect(client).to.exist; - expect(client.topology).to.exist; - expect(client.topology.description).to.exist; - expect(client.topology.description).to.have.property('type', TopologyType.Sharded); + expect(client).nested.property('topology.description.type').to.equal(TopologyType.Sharded); return done(); })(); } From c207c6852f2d81c14fd7a00f50a20055a2be7b4a Mon Sep 17 00:00:00 2001 From: Thomas Reggi Date: Mon, 12 Oct 2020 10:29:03 -0400 Subject: [PATCH 5/5] matts fixes --- test/functional/sharding_connection.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/functional/sharding_connection.test.js b/test/functional/sharding_connection.test.js index dcbbc5bd280..8d3b5ed5d8f 100644 --- a/test/functional/sharding_connection.test.js +++ b/test/functional/sharding_connection.test.js @@ -14,10 +14,11 @@ describe('Sharding (Connection)', function() { metadata: { requires: { topology: 'sharded' } }, test: function() { const client = this.configuration.newClient({}, { useUnifiedTopology: true }); - expect(client.s.options).to.have.property('useUnifiedTopology', true); return withClient(client, (client, done) => { expect(client).to.exist; - expect(client).nested.property('topology.description.type').to.equal(TopologyType.Sharded); + expect(client) + .nested.property('topology.description.type') + .to.equal(TopologyType.Sharded); return done(); })(); }