diff --git a/source/load-balancers/tests/dns-seedlist-discovery.json b/source/load-balancers/tests/dns-seedlist-discovery.json new file mode 100644 index 0000000000..fe43ada113 --- /dev/null +++ b/source/load-balancers/tests/dns-seedlist-discovery.json @@ -0,0 +1,76 @@ +{ + "description": "DNS seedlist discovery for load-balanced clusters", + "schemaVersion": "1.4", + "runOnRequirements": [ + { + "topologies": [ + "load-balanced" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "useMultipleMongoses": true, + "observeEvents": [ + "topologyDescriptionChangedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "database0" + } + } + ], + "tests": [ + { + "description": "SRV polling is disabled with loadBalanced=true", + "operations": [ + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client0", + "event": { + "topologyDescriptionChangedEvent": { + "topologyType": "LoadBalanced" + } + } + } + }, + { + "name": "wait", + "object": "testRunner", + "arguments": { + "ms": 60000 + } + }, + { + "name": "runCommand", + "object": "database0", + "arguments": { + "commandName": "ping", + "command": { + "ping": 1 + } + } + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client0", + "event": { + "topologyDescriptionChangedEvent": 2 + }, + "count": 2 + } + } + ] + } + ] +} diff --git a/source/load-balancers/tests/dns-seedlist-discovery.yml b/source/load-balancers/tests/dns-seedlist-discovery.yml new file mode 100644 index 0000000000..f5b7afa013 --- /dev/null +++ b/source/load-balancers/tests/dns-seedlist-discovery.yml @@ -0,0 +1,48 @@ +description: DNS seedlist discovery for load-balanced clusters + +schemaVersion: '1.4' + +runOnRequirements: + - topologies: [ load-balanced ] + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: true + observeEvents: + - topologyDescriptionChangedEvent + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name database0 + +tests: + - description: SRV polling is disabled with loadBalanced=true + operations: + # Wait for initial topology description events + - name: waitForEvent + object: testRunner + arguments: + client: *client0 + event: + topologyDescriptionChangedEvent: + topologyType: LoadBalanced + # Wait long enough for any SRV polling to occur (if implemented) + - name: wait + object: testRunner + arguments: + ms: 60000 + # Run an operation to check that we're still connected + - name: runCommand + object: *database0 + arguments: + commandName: ping + command: { ping: 1 } + # Verify that no additional topology events were published + - name: assertEventCount + object: testRunner + arguments: + client: *client0 + event: + topologyDescriptionChangedEvent: 2 + count: 2 # Only two events: initial Unknown -> LoadBalanced, and LoadBalanced server details diff --git a/source/load-balancers/tests/driver-sessions.json b/source/load-balancers/tests/driver-sessions.json new file mode 100644 index 0000000000..a4e0f7b563 --- /dev/null +++ b/source/load-balancers/tests/driver-sessions.json @@ -0,0 +1,89 @@ +{ + "description": "driver sessions for load-balanced clusters", + "schemaVersion": "1.4", + "runOnRequirements": [ + { + "topologies": [ + "load-balanced" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "useMultipleMongoses": true, + "observeEvents": [ + "commandStartedEvent" + ] + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "database0" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "collection0" + } + } + ], + "tests": [ + { + "description": "sessions are always supported with load-balanced topology", + "operations": [ + { + "name": "createClientSession", + "object": "client0", + "arguments": {}, + "saveResultAsEntity": "session0" + }, + { + "name": "insertOne", + "object": "collection0", + "arguments": { + "document": { + "x": 1 + }, + "session": "session0" + } + } + ] + }, + { + "description": "ServerType LoadBalancer is considered a data-bearing server", + "operations": [ + { + "name": "createClientSession", + "object": "client0", + "arguments": {}, + "saveResultAsEntity": "session1" + }, + { + "name": "runCommand", + "object": "database0", + "arguments": { + "commandName": "ping", + "command": { + "ping": 1 + }, + "session": "session1" + } + }, + { + "name": "find", + "object": "collection0", + "arguments": { + "filter": {}, + "session": "session1" + } + } + ] + } + ] +} diff --git a/source/load-balancers/tests/driver-sessions.yml b/source/load-balancers/tests/driver-sessions.yml new file mode 100644 index 0000000000..99269054ff --- /dev/null +++ b/source/load-balancers/tests/driver-sessions.yml @@ -0,0 +1,56 @@ +description: driver sessions for load-balanced clusters + +schemaVersion: '1.4' + +runOnRequirements: + - topologies: [ load-balanced ] + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: true + observeEvents: + - commandStartedEvent + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name database0 + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name collection0 + +tests: + - description: sessions are always supported with load-balanced topology + operations: + - name: createClientSession + object: *client0 + arguments: {} + saveResultAsEntity: &session0 session0 + # Perform a simple operation with the session + - name: insertOne + object: *collection0 + arguments: + document: { x: 1 } + session: *session0 + + - description: ServerType LoadBalancer is considered a data-bearing server + operations: + # The previous test already verifies this implicitly by allowing insertOne, + # but we can add additional operations + - name: createClientSession + object: *client0 + arguments: {} + saveResultAsEntity: &session1 session1 + - name: runCommand + object: *database0 + arguments: + commandName: ping + command: { ping: 1 } + session: *session1 + # Test that we can use read operations as well (which require a data-bearing server) + - name: find + object: *collection0 + arguments: + filter: {} + session: *session1 diff --git a/source/load-balancers/tests/log-messages.json b/source/load-balancers/tests/log-messages.json new file mode 100644 index 0000000000..2e8823fed0 --- /dev/null +++ b/source/load-balancers/tests/log-messages.json @@ -0,0 +1,81 @@ +{ + "description": "log messages for load-balanced clusters", + "schemaVersion": "1.4", + "runOnRequirements": [ + { + "topologies": [ + "load-balanced" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "useMultipleMongoses": true, + "logMessages": [ + "Starting topology monitoring", + "Stopped topology monitoring", + "Starting server monitoring", + "Stopped server monitoring", + "Topology description changed" + ] + } + } + ], + "tests": [ + { + "description": "proper SDAM log messages are emitted for load-balanced clusters", + "operations": [ + { + "name": "insertOne", + "object": "testRunner", + "arguments": { + "client": "client0", + "logs": [ + { + "levelContains": "info", + "componentContains": "topology", + "messageContains": "Starting topology monitoring" + }, + { + "levelContains": "info", + "componentContains": "topology", + "messageContains": "Topology description changed" + }, + { + "levelContains": "info", + "componentContains": "topology", + "messageContains": "Starting server monitoring" + } + ] + } + }, + { + "name": "close", + "object": "client0" + }, + { + "name": "assertLogMessageCount", + "object": "testRunner", + "arguments": { + "client": "client0", + "logs": [ + { + "levelContains": "info", + "componentContains": "topology", + "messageContains": "Stopped server monitoring" + }, + { + "levelContains": "info", + "componentContains": "topology", + "messageContains": "Stopped topology monitoring" + } + ], + "count": 1 + } + } + ] + } + ] +} diff --git a/source/load-balancers/tests/log-messages.yml b/source/load-balancers/tests/log-messages.yml new file mode 100644 index 0000000000..5f542f68c6 --- /dev/null +++ b/source/load-balancers/tests/log-messages.yml @@ -0,0 +1,52 @@ +description: log messages for load-balanced clusters + +schemaVersion: '1.4' + +runOnRequirements: + - topologies: [ load-balanced ] + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: true + logMessages: + - "Starting topology monitoring" + - "Stopped topology monitoring" + - "Starting server monitoring" + - "Stopped server monitoring" + - "Topology description changed" + +tests: + - description: proper SDAM log messages are emitted for load-balanced clusters + operations: + # Run a simple operation to ensure logs are captured + - name: insertOne + object: testRunner + arguments: + client: *client0 + logs: + # Only check for the presence of these log messages, not their exact format + - levelContains: info + componentContains: topology + messageContains: "Starting topology monitoring" + - levelContains: info + componentContains: topology + messageContains: "Topology description changed" + - levelContains: info + componentContains: topology + messageContains: "Starting server monitoring" + # Close the client to verify closing logs + - name: close + object: *client0 + - name: assertLogMessageCount + object: testRunner + arguments: + client: *client0 + logs: + - levelContains: info + componentContains: topology + messageContains: "Stopped server monitoring" + - levelContains: info + componentContains: topology + messageContains: "Stopped topology monitoring" + count: 1 diff --git a/source/load-balancers/tests/sdam-events.json b/source/load-balancers/tests/sdam-events.json new file mode 100644 index 0000000000..6d847b0b31 --- /dev/null +++ b/source/load-balancers/tests/sdam-events.json @@ -0,0 +1,115 @@ +{ + "description": "server discovery and monitoring for load-balanced clusters", + "schemaVersion": "1.4", + "runOnRequirements": [ + { + "topologies": [ + "load-balanced" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "client0", + "useMultipleMongoses": true, + "observeEvents": [ + "topologyOpeningEvent", + "topologyDescriptionChangedEvent", + "serverOpeningEvent", + "serverDescriptionChangedEvent", + "topologyClosedEvent", + "serverClosedEvent" + ] + } + } + ], + "tests": [ + { + "description": "proper SDAM events are emitted for load-balanced clusters", + "operations": [ + { + "name": "createCollection", + "object": "testRunner", + "arguments": { + "client": "client0", + "events": [ + { + "topologyOpeningEvent": {} + }, + { + "topologyDescriptionChangedEvent": { + "previousDescription": { + "topologyType": "Unknown", + "servers": [] + }, + "newDescription": { + "topologyType": "LoadBalanced", + "servers": [ + { + "address": { + "$$type": "string" + }, + "type": "Unknown" + } + ] + } + } + }, + { + "serverOpeningEvent": {} + }, + { + "serverDescriptionChangedEvent": { + "previousDescription": { + "address": { + "$$type": "string" + }, + "type": "Unknown" + }, + "newDescription": { + "address": { + "$$type": "string" + }, + "type": "LoadBalancer" + } + } + }, + { + "topologyDescriptionChangedEvent": { + "newDescription": { + "topologyType": "LoadBalanced", + "servers": [ + { + "address": { + "$$type": "string" + }, + "type": "LoadBalancer" + } + ] + } + } + } + ] + } + }, + { + "name": "close", + "object": "client0" + }, + { + "name": "assertEventCount", + "object": "testRunner", + "arguments": { + "client": "client0", + "event": { + "serverClosedEvent": 1, + "topologyClosedEvent": 1, + "topologyDescriptionChangedEvent": 3 + } + } + } + ] + } + ] +} diff --git a/source/load-balancers/tests/sdam-events.yml b/source/load-balancers/tests/sdam-events.yml new file mode 100644 index 0000000000..bc77924502 --- /dev/null +++ b/source/load-balancers/tests/sdam-events.yml @@ -0,0 +1,62 @@ +description: server discovery and monitoring for load-balanced clusters + +schemaVersion: '1.4' + +runOnRequirements: + - topologies: [ load-balanced ] + +createEntities: + - client: + id: &client0 client0 + useMultipleMongoses: true + observeEvents: + - topologyOpeningEvent + - topologyDescriptionChangedEvent + - serverOpeningEvent + - serverDescriptionChangedEvent + - topologyClosedEvent + - serverClosedEvent + +tests: + - description: proper SDAM events are emitted for load-balanced clusters + operations: + - name: createCollection + object: testRunner + arguments: + client: *client0 + events: + - topologyOpeningEvent: {} + - topologyDescriptionChangedEvent: + previousDescription: + topologyType: Unknown + servers: [] + newDescription: + topologyType: LoadBalanced + servers: + - address: { $$type: string } + type: Unknown + - serverOpeningEvent: {} + - serverDescriptionChangedEvent: + previousDescription: + address: { $$type: string } + type: Unknown + newDescription: + address: { $$type: string } + type: LoadBalancer + - topologyDescriptionChangedEvent: + newDescription: + topologyType: LoadBalanced + servers: + - address: { $$type: string } + type: LoadBalancer + # Close the client and verify closing events + - name: close + object: *client0 + - name: assertEventCount + object: testRunner + arguments: + client: *client0 + event: + serverClosedEvent: 1 + topologyClosedEvent: 1 + topologyDescriptionChangedEvent: 3 # Initial, server description change, and closing diff --git a/source/load-balancers/tests/uri-validation.json b/source/load-balancers/tests/uri-validation.json new file mode 100644 index 0000000000..f685185c9e --- /dev/null +++ b/source/load-balancers/tests/uri-validation.json @@ -0,0 +1,112 @@ +{ + "description": "URI validation for load-balanced clusters", + "schemaVersion": "1.4", + "runOnRequirements": [ + { + "topologies": [ + "single", + "sharded" + ] + } + ], + "createEntities": [ + { + "client": { + "id": "regularClient", + "useMultipleMongoses": false + } + }, + { + "database": { + "id": "regularDatabase", + "client": "regularClient", + "databaseName": "testdb" + } + } + ], + "tests": [ + { + "description": "error when connection string contains multiple hosts with loadBalanced=true", + "operations": [ + { + "name": "createClient", + "object": "testRunner", + "arguments": { + "clientOptions": { + "uriOptions": { + "loadBalanced": true + }, + "uriHosts": [ + "localhost:27017", + "localhost:27018" + ] + } + }, + "expectError": { + "errorContains": "cannot be used with multiple hosts" + } + } + ] + }, + { + "description": "error when connection string contains replicaSet with loadBalanced=true", + "operations": [ + { + "name": "createClient", + "object": "testRunner", + "arguments": { + "clientOptions": { + "uriOptions": { + "loadBalanced": true, + "replicaSet": "mySet" + } + } + }, + "expectError": { + "errorContains": "cannot be used with replicaSet" + } + } + ] + }, + { + "description": "error when connection string contains directConnection=true with loadBalanced=true", + "operations": [ + { + "name": "createClient", + "object": "testRunner", + "arguments": { + "clientOptions": { + "uriOptions": { + "loadBalanced": true, + "directConnection": true + } + } + }, + "expectError": { + "errorContains": "cannot be used with directConnection=true" + } + } + ] + }, + { + "description": "error when connection string contains srvMaxHosts with loadBalanced=true", + "operations": [ + { + "name": "createClient", + "object": "testRunner", + "arguments": { + "clientOptions": { + "uriOptions": { + "loadBalanced": true, + "srvMaxHosts": 2 + } + } + }, + "expectError": { + "errorContains": "cannot be used with srvMaxHosts" + } + } + ] + } + ] +} diff --git a/source/load-balancers/tests/uri-validation.yml b/source/load-balancers/tests/uri-validation.yml new file mode 100644 index 0000000000..ca97b2aefd --- /dev/null +++ b/source/load-balancers/tests/uri-validation.yml @@ -0,0 +1,68 @@ +description: URI validation for load-balanced clusters + +schemaVersion: '1.4' + +# Run on a topology that supports a single host (not replica set) +runOnRequirements: + - topologies: [ single, sharded ] + +createEntities: + - client: + id: ®ularClient regularClient + useMultipleMongoses: false + - database: + id: ®ularDatabase regularDatabase + client: *regularClient + databaseName: ®ularDatabaseName testdb + +tests: + - description: error when connection string contains multiple hosts with loadBalanced=true + operations: + - name: createClient + object: testRunner + arguments: + clientOptions: + uriOptions: + loadBalanced: true + # Use two hosts to trigger validation error + uriHosts: + - "localhost:27017" + - "localhost:27018" + expectError: + errorContains: "cannot be used with multiple hosts" + + - description: error when connection string contains replicaSet with loadBalanced=true + operations: + - name: createClient + object: testRunner + arguments: + clientOptions: + uriOptions: + loadBalanced: true + replicaSet: mySet + expectError: + errorContains: "cannot be used with replicaSet" + + - description: error when connection string contains directConnection=true with loadBalanced=true + operations: + - name: createClient + object: testRunner + arguments: + clientOptions: + uriOptions: + loadBalanced: true + directConnection: true + expectError: + errorContains: "cannot be used with directConnection=true" + + - description: error when connection string contains srvMaxHosts with loadBalanced=true + operations: + - name: createClient + object: testRunner + arguments: + clientOptions: + uriOptions: + loadBalanced: true + srvMaxHosts: 2 + expectError: + errorContains: "cannot be used with srvMaxHosts"