diff --git a/src/sdam/topology.ts b/src/sdam/topology.ts index 73b0e92a09..429a8fc5b3 100644 --- a/src/sdam/topology.ts +++ b/src/sdam/topology.ts @@ -488,6 +488,8 @@ export class Topology extends TypedEventEmitter { /** Close this topology */ close(): void { + const previousDescription = this.s.description; + if (this.s.state === STATE_CLOSED || this.s.state === STATE_CLOSING) { return; } @@ -511,6 +513,21 @@ export class Topology extends TypedEventEmitter { this.removeListener(Topology.TOPOLOGY_DESCRIPTION_CHANGED, this.s.detectShardedTopology); stateTransition(this, STATE_CLOSED); + this.s.description = new TopologyDescription( + TopologyType.Unknown, + new Map(), + this.s.options.replicaSet, + undefined, + undefined, + undefined, + this.s.options + ); + + // broadcast that topology is in closed state + this.emitAndLog( + Topology.TOPOLOGY_DESCRIPTION_CHANGED, + new TopologyDescriptionChangedEvent(this.s.id, previousDescription, this.s.description) + ); // emit an event for close this.emitAndLog(Topology.TOPOLOGY_CLOSED, new TopologyClosedEvent(this.s.id)); diff --git a/test/integration/server-discovery-and-monitoring/server_discover_and_monitoring.test.ts b/test/integration/server-discovery-and-monitoring/server_discover_and_monitoring.test.ts deleted file mode 100644 index d0b3fc9944..0000000000 --- a/test/integration/server-discovery-and-monitoring/server_discover_and_monitoring.test.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { loadSpecTests } from '../../spec'; -import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; - -describe('SDAM Unified Tests (Node Driver)', function () { - // TODO(NODE-5723): Remove this once the actual unified tests (test/spec/server-disovery-and-monitoring/logging) are passing - const clonedAndAlteredSpecTests = loadSpecTests( - '../integration/server-discovery-and-monitoring/unified-sdam-node-specs' - ); - runUnifiedSuite(clonedAndAlteredSpecTests); -}); diff --git a/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-loadbalanced.json b/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-loadbalanced.json deleted file mode 100644 index 7f4431072d..0000000000 --- a/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-loadbalanced.json +++ /dev/null @@ -1,150 +0,0 @@ -{ - "description": "loadbalanced-logging-node-driver", - "schemaVersion": "1.16", - "runOnRequirements": [ - { - "topologies": [ - "load-balanced" - ], - "minServerVersion": "4.4" - } - ], - "tests": [ - { - "description": "Topology lifecycle", - "operations": [ - { - "name": "createEntities", - "object": "testRunner", - "arguments": { - "entities": [ - { - "client": { - "id": "client", - "observeLogMessages": { - "topology": "debug" - }, - "observeEvents": [ - "topologyDescriptionChangedEvent" - ] - } - } - ] - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "client": "client", - "event": { - "topologyDescriptionChangedEvent": {} - }, - "count": 2 - } - }, - { - "name": "close", - "object": "client" - } - ], - "expectLogMessages": [ - { - "client": "client", - "messages": [ - { - "level": "debug", - "component": "topology", - "data": { - "message": "Starting topology monitoring", - "topologyId": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Topology description changed", - "topologyId": { - "$$exists": true - }, - "previousDescription": { - "$$exists": true - }, - "newDescription": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Starting server monitoring", - "topologyId": { - "$$exists": true - }, - "serverHost": { - "$$type": "string" - }, - "serverPort": { - "$$type": [ - "int", - "long" - ] - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Topology description changed", - "topologyId": { - "$$exists": true - }, - "previousDescription": { - "$$exists": true - }, - "newDescription": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Stopped server monitoring", - "topologyId": { - "$$exists": true - }, - "serverHost": { - "$$type": "string" - }, - "serverPort": { - "$$type": [ - "int", - "long" - ] - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Stopped topology monitoring", - "topologyId": { - "$$exists": true - } - } - } - ] - } - ] - } - ] -} diff --git a/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-replicaset.json b/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-replicaset.json deleted file mode 100644 index 189d3d6866..0000000000 --- a/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-replicaset.json +++ /dev/null @@ -1,238 +0,0 @@ -{ - "description": "replicaset-logging-node-driver", - "schemaVersion": "1.16", - "runOnRequirements": [ - { - "topologies": [ - "replicaset" - ], - "minServerVersion": "4.4" - } - ], - "createEntities": [ - { - "client": { - "id": "setupClient" - } - } - ], - "tests": [ - { - "description": "Topology lifecycle", - "operations": [ - { - "name": "createEntities", - "object": "testRunner", - "arguments": { - "entities": [ - { - "client": { - "id": "client", - "observeLogMessages": { - "topology": "debug" - }, - "observeEvents": [ - "topologyDescriptionChangedEvent" - ] - } - } - ] - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "client": "client", - "event": { - "topologyDescriptionChangedEvent": {} - }, - "count": 4 - } - }, - { - "name": "close", - "object": "client" - } - ], - "expectLogMessages": [ - { - "client": "client", - "ignoreMessages": [ - { - "level": "debug", - "component": "topology", - "data": { - "message": "Starting server monitoring" - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Server heartbeat started" - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Server heartbeat succeeded" - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Server heartbeat failed" - } - } - ], - "messages": [ - { - "level": "debug", - "component": "topology", - "data": { - "message": "Starting topology monitoring", - "topologyId": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Topology description changed", - "topologyId": { - "$$exists": true - }, - "previousDescription": { - "$$exists": true - }, - "newDescription": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Topology description changed", - "topologyId": { - "$$exists": true - }, - "previousDescription": { - "$$exists": true - }, - "newDescription": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Topology description changed", - "topologyId": { - "$$exists": true - }, - "previousDescription": { - "$$exists": true - }, - "newDescription": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Topology description changed", - "topologyId": { - "$$exists": true - }, - "previousDescription": { - "$$exists": true - }, - "newDescription": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Stopped server monitoring", - "topologyId": { - "$$exists": true - }, - "serverHost": { - "$$type": "string" - }, - "serverPort": { - "$$type": [ - "int", - "long" - ] - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Stopped server monitoring", - "topologyId": { - "$$exists": true - }, - "serverHost": { - "$$type": "string" - }, - "serverPort": { - "$$type": [ - "int", - "long" - ] - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Stopped server monitoring", - "topologyId": { - "$$exists": true - }, - "serverHost": { - "$$type": "string" - }, - "serverPort": { - "$$type": [ - "int", - "long" - ] - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Stopped topology monitoring", - "topologyId": { - "$$exists": true - } - } - } - ] - } - ] - } - ] -} diff --git a/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-sharded.json b/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-sharded.json deleted file mode 100644 index 4edbd5425f..0000000000 --- a/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-sharded.json +++ /dev/null @@ -1,206 +0,0 @@ -{ - "description": "sharded-logging-node-driver", - "schemaVersion": "1.16", - "runOnRequirements": [ - { - "topologies": [ - "sharded" - ], - "minServerVersion": "4.4" - } - ], - "createEntities": [ - { - "client": { - "id": "setupClient", - "useMultipleMongoses": false - } - } - ], - "tests": [ - { - "description": "Topology lifecycle", - "operations": [ - { - "name": "createEntities", - "object": "testRunner", - "arguments": { - "entities": [ - { - "client": { - "id": "client", - "observeLogMessages": { - "topology": "debug" - }, - "observeEvents": [ - "topologyDescriptionChangedEvent" - ], - "useMultipleMongoses": true - } - } - ] - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "client": "client", - "event": { - "topologyDescriptionChangedEvent": {} - }, - "count": 3 - } - }, - { - "name": "close", - "object": "client" - } - ], - "expectLogMessages": [ - { - "client": "client", - "ignoreMessages": [ - { - "level": "debug", - "component": "topology", - "data": { - "message": "Starting server monitoring" - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Server heartbeat started" - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Server heartbeat succeeded" - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Server heartbeat failed" - } - } - ], - "messages": [ - { - "level": "debug", - "component": "topology", - "data": { - "message": "Starting topology monitoring", - "topologyId": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Topology description changed", - "topologyId": { - "$$exists": true - }, - "previousDescription": { - "$$exists": true - }, - "newDescription": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Topology description changed", - "topologyId": { - "$$exists": true - }, - "previousDescription": { - "$$exists": true - }, - "newDescription": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Topology description changed", - "topologyId": { - "$$exists": true - }, - "previousDescription": { - "$$exists": true - }, - "newDescription": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Stopped server monitoring", - "topologyId": { - "$$exists": true - }, - "serverHost": { - "$$type": "string" - }, - "serverPort": { - "$$type": [ - "int", - "long" - ] - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Stopped server monitoring", - "topologyId": { - "$$exists": true - }, - "serverHost": { - "$$type": "string" - }, - "serverPort": { - "$$type": [ - "int", - "long" - ] - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Stopped topology monitoring", - "topologyId": { - "$$exists": true - } - } - } - ] - } - ] - } - ] -} - diff --git a/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-standalone.json b/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-standalone.json deleted file mode 100644 index b1139d2e74..0000000000 --- a/test/integration/server-discovery-and-monitoring/unified-sdam-node-specs/logging-standalone.json +++ /dev/null @@ -1,180 +0,0 @@ -{ - "description": "standalone-logging-node-driver", - "schemaVersion": "1.16", - "runOnRequirements": [ - { - "topologies": [ - "single" - ], - "minServerVersion": "4.4" - } - ], - "createEntities": [ - { - "client": { - "id": "setupClient" - } - } - ], - "tests": [ - { - "description": "Topology lifecycle", - "operations": [ - { - "name": "createEntities", - "object": "testRunner", - "arguments": { - "entities": [ - { - "client": { - "id": "client", - "observeLogMessages": { - "topology": "debug" - }, - "observeEvents": [ - "topologyDescriptionChangedEvent" - ] - } - } - ] - } - }, - { - "name": "waitForEvent", - "object": "testRunner", - "arguments": { - "client": "client", - "event": { - "topologyDescriptionChangedEvent": {} - }, - "count": 2 - } - }, - { - "name": "close", - "object": "client" - } - ], - "expectLogMessages": [ - { - "client": "client", - "ignoreMessages": [ - { - "level": "debug", - "component": "topology", - "data": { - "message": "Server heartbeat started" - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Server heartbeat succeeded" - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Server heartbeat failed" - } - } - ], - "messages": [ - { - "level": "debug", - "component": "topology", - "data": { - "message": "Starting topology monitoring", - "topologyId": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Topology description changed", - "topologyId": { - "$$exists": true - }, - "previousDescription": { - "$$exists": true - }, - "newDescription": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Starting server monitoring", - "topologyId": { - "$$exists": true - }, - "serverHost": { - "$$type": "string" - }, - "serverPort": { - "$$type": [ - "int", - "long" - ] - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Topology description changed", - "topologyId": { - "$$exists": true - }, - "previousDescription": { - "$$exists": true - }, - "newDescription": { - "$$exists": true - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Stopped server monitoring", - "topologyId": { - "$$exists": true - }, - "serverHost": { - "$$type": "string" - }, - "serverPort": { - "$$type": [ - "int", - "long" - ] - } - } - }, - { - "level": "debug", - "component": "topology", - "data": { - "message": "Stopped topology monitoring", - "topologyId": { - "$$exists": true - } - } - } - ] - } - ] - } - ] -} diff --git a/test/manual/socks5.test.ts b/test/manual/socks5.test.ts index a37907aff6..f8c07a2467 100644 --- a/test/manual/socks5.test.ts +++ b/test/manual/socks5.test.ts @@ -302,7 +302,7 @@ describe('Socks5 Connectivity', function () { async function testConnection(connectionString, clientOptions) { const client = new MongoClient(connectionString, clientOptions); let topologyType; - client.on('topologyDescriptionChanged', ev => (topologyType = ev.newDescription.type)); + client.on('topologyDescriptionChanged', ev => (topologyType = ev.previousDescription.type)); try { await client.connect(); diff --git a/test/spec/server-discovery-and-monitoring/unified/loadbalanced-emit-topology-changed-before-close.json b/test/spec/server-discovery-and-monitoring/unified/loadbalanced-emit-topology-changed-before-close.json new file mode 100644 index 0000000000..30c0657630 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/unified/loadbalanced-emit-topology-changed-before-close.json @@ -0,0 +1,88 @@ +{ + "description": "loadbalanced-emit-topology-description-changed-before-close", + "schemaVersion": "1.20", + "runOnRequirements": [ + { + "topologies": [ + "load-balanced" + ], + "minServerVersion": "4.4" + } + ], + "tests": [ + { + "description": "Topology lifecycle", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "observeEvents": [ + "topologyDescriptionChangedEvent", + "topologyOpeningEvent", + "topologyClosedEvent" + ] + } + } + ] + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "topologyDescriptionChangedEvent": {} + }, + "count": 2 + } + }, + { + "name": "close", + "object": "client" + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "sdam", + "events": [ + { + "topologyOpeningEvent": {} + }, + { + "topologyDescriptionChangedEvent": { + "previousDescription": { + "type": "Unknown" + }, + "newDescription": {} + } + }, + { + "topologyDescriptionChangedEvent": { + "newDescription": { + "type": "LoadBalanced" + } + } + }, + { + "topologyDescriptionChangedEvent": { + "newDescription": { + "type": "Unknown" + } + } + }, + { + "topologyClosedEvent": {} + } + ] + } + ] + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/unified/loadbalanced-emit-topology-changed-before-close.yml b/test/spec/server-discovery-and-monitoring/unified/loadbalanced-emit-topology-changed-before-close.yml new file mode 100644 index 0000000000..c919a8cf8b --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/unified/loadbalanced-emit-topology-changed-before-close.yml @@ -0,0 +1,49 @@ +description: "loadbalanced-emit-topology-description-changed-before-close" + +schemaVersion: "1.20" + +runOnRequirements: + - topologies: + - load-balanced + minServerVersion: "4.4" # awaitable hello + +tests: + - description: "Topology lifecycle" + operations: + - name: createEntities + object: testRunner + arguments: + entities: + - client: + id: &client client + observeEvents: + - topologyDescriptionChangedEvent + - topologyOpeningEvent + - topologyClosedEvent + # ensure the topology has been fully discovered before closing the client. + # expected events are initial server discovery and server connect event. + - name: waitForEvent + object: testRunner + arguments: + client: *client + event: + topologyDescriptionChangedEvent: {} + count: 2 + - name: close + object: *client + expectEvents: + - client: *client + eventType: sdam + events: + - topologyOpeningEvent: {} + - topologyDescriptionChangedEvent: # unknown -> unknown w disconnected server + previousDescription: + type: "Unknown" + newDescription: {} + - topologyDescriptionChangedEvent: # unknown w disconnected server -> loadBalanced + newDescription: + type: "LoadBalanced" + - topologyDescriptionChangedEvent: # loadbalanced -> unknown + newDescription: + type: "Unknown" + - topologyClosedEvent: {} diff --git a/test/spec/server-discovery-and-monitoring/unified/logging-loadbalanced.json b/test/spec/server-discovery-and-monitoring/unified/logging-loadbalanced.json index 45440d2557..0ad3b0ceaa 100644 --- a/test/spec/server-discovery-and-monitoring/unified/logging-loadbalanced.json +++ b/test/spec/server-discovery-and-monitoring/unified/logging-loadbalanced.json @@ -132,6 +132,22 @@ } } }, + { + "level": "debug", + "component": "topology", + "data": { + "message": "Topology description changed", + "topologyId": { + "$$exists": true + }, + "previousDescription": { + "$$exists": true + }, + "newDescription": { + "$$exists": true + } + } + }, { "level": "debug", "component": "topology", diff --git a/test/spec/server-discovery-and-monitoring/unified/logging-loadbalanced.yml b/test/spec/server-discovery-and-monitoring/unified/logging-loadbalanced.yml index 3f6058270f..432ec354ed 100644 --- a/test/spec/server-discovery-and-monitoring/unified/logging-loadbalanced.yml +++ b/test/spec/server-discovery-and-monitoring/unified/logging-loadbalanced.yml @@ -67,8 +67,15 @@ tests: topologyId: { $$exists: true } serverHost: { $$type: string } serverPort: { $$type: [int, long] } + - level: debug + component: topology + data: + message: "Topology description changed" + topologyId: { $$exists: true } + previousDescription: { $$exists: true } # loadBalanced topology + newDescription: { $$exists: true } # unknown topology - level: debug component: topology data: message: "Stopped topology monitoring" - topologyId: { $$exists: true } \ No newline at end of file + topologyId: { $$exists: true } diff --git a/test/spec/server-discovery-and-monitoring/unified/replicaset-emit-topology-changed-before-close.json b/test/spec/server-discovery-and-monitoring/unified/replicaset-emit-topology-changed-before-close.json new file mode 100644 index 0000000000..066a4ffee5 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/unified/replicaset-emit-topology-changed-before-close.json @@ -0,0 +1,89 @@ +{ + "description": "replicaset-emit-topology-description-changed-before-close", + "schemaVersion": "1.20", + "runOnRequirements": [ + { + "topologies": [ + "replicaset" + ], + "minServerVersion": "4.4" + } + ], + "tests": [ + { + "description": "Topology lifecycle", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "observeEvents": [ + "topologyDescriptionChangedEvent", + "topologyOpeningEvent", + "topologyClosedEvent" + ] + } + } + ] + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "topologyDescriptionChangedEvent": {} + }, + "count": 4 + } + }, + { + "name": "close", + "object": "client" + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "sdam", + "ignoreExtraEvents": false, + "events": [ + { + "topologyOpeningEvent": {} + }, + { + "topologyDescriptionChangedEvent": {} + }, + { + "topologyDescriptionChangedEvent": {} + }, + { + "topologyDescriptionChangedEvent": {} + }, + { + "topologyDescriptionChangedEvent": {} + }, + { + "topologyDescriptionChangedEvent": { + "previousDescription": { + "type": "ReplicaSetWithPrimary" + }, + "newDescription": { + "type": "Unknown" + } + } + }, + { + "topologyClosedEvent": {} + } + ] + } + ] + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/unified/replicaset-emit-topology-changed-before-close.yml b/test/spec/server-discovery-and-monitoring/unified/replicaset-emit-topology-changed-before-close.yml new file mode 100644 index 0000000000..d0a1158ea9 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/unified/replicaset-emit-topology-changed-before-close.yml @@ -0,0 +1,49 @@ +description: "replicaset-emit-topology-description-changed-before-close" + +schemaVersion: "1.20" + +runOnRequirements: + - topologies: + - replicaset + minServerVersion: "4.4" # awaitable hello + +tests: + - description: "Topology lifecycle" + operations: + - name: createEntities + object: testRunner + arguments: + entities: + - client: + id: &client client + observeEvents: + - topologyDescriptionChangedEvent + - topologyOpeningEvent + - topologyClosedEvent + # ensure the topology has been fully discovered before closing the client. + # expected events are initial server discovery and 3 server connect events. + - name: waitForEvent + object: testRunner + arguments: + client: *client + event: + topologyDescriptionChangedEvent: {} + count: 4 + - name: close + object: *client + expectEvents: + - client: *client + eventType: sdam + ignoreExtraEvents: false + events: + - topologyOpeningEvent: {} + - topologyDescriptionChangedEvent: {} # unknown -> replset no primary + - topologyDescriptionChangedEvent: {} # server connected + - topologyDescriptionChangedEvent: {} # server connected + - topologyDescriptionChangedEvent: {} # server connected + - topologyDescriptionChangedEvent: # replicaset -> unknown + previousDescription: + type: "ReplicaSetWithPrimary" + newDescription: + type: "Unknown" + - topologyClosedEvent: {} diff --git a/test/spec/server-discovery-and-monitoring/unified/sharded-emit-topology-changed-before-close.json b/test/spec/server-discovery-and-monitoring/unified/sharded-emit-topology-changed-before-close.json new file mode 100644 index 0000000000..98fb585531 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/unified/sharded-emit-topology-changed-before-close.json @@ -0,0 +1,108 @@ +{ + "description": "sharded-emit-topology-description-changed-before-close", + "schemaVersion": "1.20", + "runOnRequirements": [ + { + "topologies": [ + "sharded" + ], + "minServerVersion": "4.4" + } + ], + "tests": [ + { + "description": "Topology lifecycle", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "observeEvents": [ + "topologyDescriptionChangedEvent", + "topologyOpeningEvent", + "topologyClosedEvent" + ], + "useMultipleMongoses": true + } + } + ] + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "topologyDescriptionChangedEvent": {} + }, + "count": 3 + } + }, + { + "name": "close", + "object": "client" + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "sdam", + "ignoreExtraEvents": false, + "events": [ + { + "topologyOpeningEvent": {} + }, + { + "topologyDescriptionChangedEvent": { + "previousDescription": { + "type": "Unknown" + }, + "newDescription": { + "type": "Unknown" + } + } + }, + { + "topologyDescriptionChangedEvent": { + "previousDescription": { + "type": "Unknown" + }, + "newDescription": { + "type": "Sharded" + } + } + }, + { + "topologyDescriptionChangedEvent": { + "previousDescription": { + "type": "Sharded" + }, + "newDescription": { + "type": "Sharded" + } + } + }, + { + "topologyDescriptionChangedEvent": { + "previousDescription": { + "type": "Sharded" + }, + "newDescription": { + "type": "Unknown" + } + } + }, + { + "topologyClosedEvent": {} + } + ] + } + ] + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/unified/sharded-emit-topology-changed-before-close.yml b/test/spec/server-discovery-and-monitoring/unified/sharded-emit-topology-changed-before-close.yml new file mode 100644 index 0000000000..cb6cc5ad4d --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/unified/sharded-emit-topology-changed-before-close.yml @@ -0,0 +1,62 @@ +description: "sharded-emit-topology-description-changed-before-close" + +schemaVersion: "1.20" + +runOnRequirements: + - topologies: + - sharded + minServerVersion: "4.4" # awaitable hello + +tests: + - description: "Topology lifecycle" + operations: + - name: createEntities + object: testRunner + arguments: + entities: + - client: + id: &client client + observeEvents: + - topologyDescriptionChangedEvent + - topologyOpeningEvent + - topologyClosedEvent + useMultipleMongoses: true + # ensure the topology has been fully discovered before closing the client. + # expected events are initial cluster type change from unknown to sharded and connect events + # for each of 2 servers + - name: waitForEvent + object: testRunner + arguments: + client: *client + event: + topologyDescriptionChangedEvent: {} + count: 3 + - name: close + object: *client + expectEvents: + - client: *client + eventType: sdam + ignoreExtraEvents: false + events: + - topologyOpeningEvent: {} + - topologyDescriptionChangedEvent: # unknown -> unknown w disconnected server + previousDescription: + type: "Unknown" + newDescription: + type: "Unknown" + - topologyDescriptionChangedEvent: # server connected + previousDescription: + type: "Unknown" + newDescription: + type: "Sharded" + - topologyDescriptionChangedEvent: # server connected + previousDescription: + type: "Sharded" + newDescription: + type: "Sharded" + - topologyDescriptionChangedEvent: # sharded -> unknown + previousDescription: + type: "Sharded" + newDescription: + type: "Unknown" + - topologyClosedEvent: {} diff --git a/test/spec/server-discovery-and-monitoring/unified/standalone-emit-topology-changed-before-close.json b/test/spec/server-discovery-and-monitoring/unified/standalone-emit-topology-changed-before-close.json new file mode 100644 index 0000000000..27b5444d54 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/unified/standalone-emit-topology-changed-before-close.json @@ -0,0 +1,97 @@ +{ + "description": "standalone-emit-topology-description-changed-before-close", + "schemaVersion": "1.20", + "runOnRequirements": [ + { + "topologies": [ + "single" + ], + "minServerVersion": "4.4" + } + ], + "tests": [ + { + "description": "Topology lifecycle", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "observeEvents": [ + "topologyDescriptionChangedEvent", + "topologyOpeningEvent", + "topologyClosedEvent" + ] + } + } + ] + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "topologyDescriptionChangedEvent": {} + }, + "count": 2 + } + }, + { + "name": "close", + "object": "client" + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "sdam", + "ignoreExtraEvents": false, + "events": [ + { + "topologyOpeningEvent": {} + }, + { + "topologyDescriptionChangedEvent": { + "previousDescription": { + "type": "Unknown" + }, + "newDescription": { + "type": "Unknown" + } + } + }, + { + "topologyDescriptionChangedEvent": { + "previousDescription": { + "type": "Unknown" + }, + "newDescription": { + "type": "Single" + } + } + }, + { + "topologyDescriptionChangedEvent": { + "previousDescription": { + "type": "Single" + }, + "newDescription": { + "type": "Unknown" + } + } + }, + { + "topologyClosedEvent": {} + } + ] + } + ] + } + ] +} diff --git a/test/spec/server-discovery-and-monitoring/unified/standalone-emit-topology-changed-before-close.yml b/test/spec/server-discovery-and-monitoring/unified/standalone-emit-topology-changed-before-close.yml new file mode 100644 index 0000000000..20fa380bd5 --- /dev/null +++ b/test/spec/server-discovery-and-monitoring/unified/standalone-emit-topology-changed-before-close.yml @@ -0,0 +1,55 @@ +description: "standalone-emit-topology-description-changed-before-close" + +schemaVersion: "1.20" + +runOnRequirements: + - topologies: + - single + minServerVersion: "4.4" # awaitable hello + +tests: + - description: "Topology lifecycle" + operations: + - name: createEntities + object: testRunner + arguments: + entities: + - client: + id: &client client + observeEvents: + - topologyDescriptionChangedEvent + - topologyOpeningEvent + - topologyClosedEvent + # ensure the topology has been fully discovered before closing the client. + # expected events are initial server discovery and server connect event. + - name: waitForEvent + object: testRunner + arguments: + client: *client + event: + topologyDescriptionChangedEvent: {} + count: 2 + - name: close + object: *client + expectEvents: + - client: *client + eventType: sdam + ignoreExtraEvents: false + events: + - topologyOpeningEvent: {} + - topologyDescriptionChangedEvent: # unknown -> unknown w disconnected server + previousDescription: + type: "Unknown" + newDescription: + type: "Unknown" + - topologyDescriptionChangedEvent: # unknown w disconnected server -> standalone + previousDescription: + type: "Unknown" + newDescription: + type: "Single" + - topologyDescriptionChangedEvent: # standalone -> unknown + previousDescription: + type: "Single" + newDescription: + type: "Unknown" + - topologyClosedEvent: {} diff --git a/test/tools/unified-spec-runner/match.ts b/test/tools/unified-spec-runner/match.ts index 4808244e29..4bc05479ef 100644 --- a/test/tools/unified-spec-runner/match.ts +++ b/test/tools/unified-spec-runner/match.ts @@ -621,7 +621,7 @@ function compareEvents( ); } } else { - expect.fail(`Encountered unexpected event - ${inspect(actualEvent)}`); + expect.fail(`Encountered unexpected event - ${inspect(actualEvent)} `); } } } @@ -724,7 +724,7 @@ export function expectErrorCheck( expected: ExpectedError, entities: EntitiesMap ): void { - const expectMessage = `\n\nOriginal Error Stack:\n${error.stack}\n\n`; + const expectMessage = `\n\nOriginal Error Stack: \n${error.stack} \n\n`; if (!isMongoCryptError(error)) { expect(error, expectMessage).to.be.instanceOf(MongoError); @@ -755,7 +755,7 @@ export function expectErrorCheck( for (const errorLabel of expected.errorLabelsContain) { expect( mongoError.hasErrorLabel(errorLabel), - `Error was supposed to have label ${errorLabel}, has [${mongoError.errorLabels}] -- ${expectMessage}` + `Error was supposed to have label ${errorLabel}, has[${mongoError.errorLabels}]--${expectMessage} ` ).to.be.true; } } @@ -765,7 +765,7 @@ export function expectErrorCheck( for (const errorLabel of expected.errorLabelsOmit) { expect( mongoError.hasErrorLabel(errorLabel), - `Error was not supposed to have label ${errorLabel}, has [${mongoError.errorLabels}] -- ${expectMessage}` + `Error was not supposed to have label ${errorLabel}, has[${mongoError.errorLabels}]--${expectMessage} ` ).to.be.false; } }