diff --git a/test/integration/server-discovery-and-monitoring/server_discovery_and_monitoring.spec.test.ts b/test/integration/server-discovery-and-monitoring/server_discovery_and_monitoring.spec.test.ts index 085899a6b86..a6b92496212 100644 --- a/test/integration/server-discovery-and-monitoring/server_discovery_and_monitoring.spec.test.ts +++ b/test/integration/server-discovery-and-monitoring/server_discovery_and_monitoring.spec.test.ts @@ -3,11 +3,26 @@ import * as path from 'path'; import { loadSpecTests } from '../../spec'; import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner'; +const skipTable: { pattern: string; reason: string }[] = [ + { + pattern: 'Topology lifecycle', + reason: 'TODO(NODE-5723): Need to implement DRIVERS-2711 spec change' + }, + { + pattern: 'connect with serverMonitoringMode=stream >=4.4', + reason: 'TODO(NODE-6045): Ensure that first server hearbeat does not report that it is awaited' + }, + { + pattern: 'connect with serverMonitoringMode=auto >=4.4', + reason: 'TODO(NODE-6045): Ensure that first server hearbeat does not report that it is awaited' + } +]; + describe('SDAM Unified Tests (Spec)', function () { const specTests = loadSpecTests(path.join('server-discovery-and-monitoring', 'unified')); runUnifiedSuite(specTests, test => { - if (['Topology lifecycle'].includes(test.description)) { - return 'see NODE-5723'; + for (const { pattern, reason } of skipTable) { + if (test.description.includes(pattern)) return reason; } return false; }); diff --git a/test/spec/unified-test-format/valid-pass/expectedEventsForClient-topologyDescriptionChangedEvent.json b/test/spec/unified-test-format/valid-pass/expectedEventsForClient-topologyDescriptionChangedEvent.json new file mode 100644 index 00000000000..cf7bd60826b --- /dev/null +++ b/test/spec/unified-test-format/valid-pass/expectedEventsForClient-topologyDescriptionChangedEvent.json @@ -0,0 +1,68 @@ +{ + "description": "expectedEventsForClient-topologyDescriptionChangedEvent", + "schemaVersion": "1.20", + "runOnRequirements": [ + { + "topologies": [ + "replicaset" + ], + "minServerVersion": "4.4" + } + ], + "tests": [ + { + "description": "can assert on values of newDescription and previousDescription fields", + "operations": [ + { + "name": "createEntities", + "object": "testRunner", + "arguments": { + "entities": [ + { + "client": { + "id": "client", + "uriOptions": { + "directConnection": true + }, + "observeEvents": [ + "topologyDescriptionChangedEvent" + ] + } + } + ] + } + }, + { + "name": "waitForEvent", + "object": "testRunner", + "arguments": { + "client": "client", + "event": { + "topologyDescriptionChangedEvent": {} + }, + "count": 1 + } + } + ], + "expectEvents": [ + { + "client": "client", + "eventType": "sdam", + "ignoreExtraEvents": true, + "events": [ + { + "topologyDescriptionChangedEvent": { + "previousDescription": { + "type": "Unknown" + }, + "newDescription": { + "type": "Single" + } + } + } + ] + } + ] + } + ] +} diff --git a/test/spec/unified-test-format/valid-pass/expectedEventsForClient-topologyDescriptionChangedEvent.yml b/test/spec/unified-test-format/valid-pass/expectedEventsForClient-topologyDescriptionChangedEvent.yml new file mode 100644 index 00000000000..c8dacc391e1 --- /dev/null +++ b/test/spec/unified-test-format/valid-pass/expectedEventsForClient-topologyDescriptionChangedEvent.yml @@ -0,0 +1,40 @@ +description: "expectedEventsForClient-topologyDescriptionChangedEvent" + +schemaVersion: "1.20" + +runOnRequirements: + - topologies: + - replicaset + minServerVersion: "4.4" # awaitable hello + +tests: + - description: "can assert on values of newDescription and previousDescription fields" + operations: + - name: createEntities + object: testRunner + arguments: + entities: + - client: + id: &client client + uriOptions: + directConnection: true + observeEvents: + - topologyDescriptionChangedEvent + - name: waitForEvent + object: testRunner + arguments: + client: *client + event: + topologyDescriptionChangedEvent: {} + count: 1 + expectEvents: + - client: *client + eventType: sdam + ignoreExtraEvents: true + events: + - topologyDescriptionChangedEvent: + previousDescription: + type: "Unknown" + newDescription: + type: "Single" + diff --git a/test/tools/unified-spec-runner/match.ts b/test/tools/unified-spec-runner/match.ts index e12062bf85c..4808244e295 100644 --- a/test/tools/unified-spec-runner/match.ts +++ b/test/tools/unified-spec-runner/match.ts @@ -561,63 +561,65 @@ function compareEvents( ); } } - return; } else if (expectedEvent.serverHeartbeatStartedEvent) { expect(actualEvent).to.be.instanceOf(ServerHeartbeatStartedEvent); const expectedSdamEvent = expectedEvent.serverHeartbeatStartedEvent; for (const property of Object.keys(expectedSdamEvent)) { expect(actualEvent[property]).to.equal(expectedSdamEvent[property]); } - return; } else if (expectedEvent.serverHeartbeatFailedEvent) { expect(actualEvent).to.be.instanceOf(ServerHeartbeatFailedEvent); const expectedSdamEvent = expectedEvent.serverHeartbeatFailedEvent; for (const property of Object.keys(expectedSdamEvent)) { expect(actualEvent[property]).to.equal(expectedSdamEvent[property]); } - return; } else if (expectedEvent.serverHeartbeatSucceededEvent) { expect(actualEvent).to.be.instanceOf(ServerHeartbeatSucceededEvent); const expectedSdamEvent = expectedEvent.serverHeartbeatSucceededEvent; for (const property of Object.keys(expectedSdamEvent)) { expect(actualEvent[property]).to.equal(expectedSdamEvent[property]); } - return; } else if (expectedEvent.serverOpeningEvent) { expect(actualEvent).to.be.instanceOf(ServerOpeningEvent); const expectedSdamEvent = expectedEvent.serverOpeningEvent; for (const property of Object.keys(expectedSdamEvent)) { expect(actualEvent[property]).to.equal(expectedSdamEvent[property]); } - return; } else if (expectedEvent.serverClosedEvent) { expect(actualEvent).to.be.instanceOf(ServerClosedEvent); const expectedSdamEvent = expectedEvent.serverClosedEvent; for (const property of Object.keys(expectedSdamEvent)) { expect(actualEvent[property]).to.equal(expectedSdamEvent[property]); } - return; } else if (expectedEvent.topologyOpeningEvent) { expect(actualEvent).to.be.instanceOf(TopologyOpeningEvent); const expectedSdamEvent = expectedEvent.topologyOpeningEvent; for (const property of Object.keys(expectedSdamEvent)) { expect(actualEvent[property]).to.equal(expectedSdamEvent[property]); } - return; - } else if (expectedEvent.topologyClosingEvent) { + } else if (expectedEvent.topologyClosedEvent) { expect(actualEvent).to.be.instanceOf(TopologyClosedEvent); - const expectedSdamEvent = expectedEvent.topologyClosingEvent; + const expectedSdamEvent = expectedEvent.topologyClosedEvent; for (const property of Object.keys(expectedSdamEvent)) { expect(actualEvent[property]).to.equal(expectedSdamEvent[property]); } - return; } else if (expectedEvent.topologyDescriptionChangedEvent) { expect(actualEvent).to.be.instanceOf(TopologyDescriptionChangedEvent); + + const actualTopChangedEvent = actualEvent as TopologyDescriptionChangedEvent; const expectedSdamEvent = expectedEvent.topologyDescriptionChangedEvent; - for (const property of Object.keys(expectedSdamEvent)) { - expect(actualEvent[property]).to.equal(expectedSdamEvent[property]); + + if (expectedSdamEvent.previousDescription?.type) { + expect(actualTopChangedEvent.previousDescription.type).to.equal( + expectedSdamEvent.previousDescription.type + ); + } + + if (expectedSdamEvent.newDescription?.type) { + expect(actualTopChangedEvent.newDescription.type).to.equal( + expectedSdamEvent.newDescription.type + ); } - return; } else { expect.fail(`Encountered unexpected event - ${inspect(actualEvent)}`); } diff --git a/test/tools/unified-spec-runner/schema.ts b/test/tools/unified-spec-runner/schema.ts index 353231cb998..6fceee9a6a5 100644 --- a/test/tools/unified-spec-runner/schema.ts +++ b/test/tools/unified-spec-runner/schema.ts @@ -7,6 +7,7 @@ import type { ServerApiVersion, SeverityLevel, TagSet, + TopologyType, W } from '../../mongodb'; import { type TestConfiguration } from '../runner/config'; @@ -95,7 +96,7 @@ export interface UnifiedSuite { tests: Test[]; _yamlAnchors?: Document; } -export const TopologyType = Object.freeze({ +export const TopologyName = Object.freeze({ single: 'single', replicaset: 'replicaset', sharded: 'sharded', @@ -103,13 +104,13 @@ export const TopologyType = Object.freeze({ loadBalanced: 'load-balanced' } as const); -export type TopologyId = (typeof TopologyType)[keyof typeof TopologyType]; +export type TopologyName = (typeof TopologyName)[keyof typeof TopologyName]; export interface RunOnRequirement { serverless?: 'forbid' | 'allow' | 'require'; auth?: boolean; maxServerVersion?: string; minServerVersion?: string; - topologies?: TopologyId[]; + topologies?: TopologyName[]; serverParameters?: Document; csfle?: boolean; } @@ -314,6 +315,7 @@ export interface ExpectedCmapEvent { connectionCheckedOutEvent?: Record; connectionCheckedInEvent?: Record; } + export interface ExpectedSdamEvent { serverDescriptionChangedEvent?: { previousDescription?: { @@ -336,16 +338,16 @@ export interface ExpectedSdamEvent { topologyDescriptionChangedEvent?: { topologyId?: any; previousDescription?: { - type?: string; + type?: TopologyType; }; newDescription?: { - type?: string; + type?: TopologyType; }; }; topologyOpeningEvent?: { topologyId?: any; }; - topologyClosingEvent?: { + topologyClosedEvent?: { topologyId?: any; }; serverOpeningEvent?: {