From 27f832a2134e24f59c76af6110541dcd6346e6c4 Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 18 Apr 2024 13:53:37 -0400 Subject: [PATCH] Impleent spec test --- test/tools/unified-spec-runner/match.ts | 24 +++++++++++++----------- test/tools/unified-spec-runner/schema.ts | 6 ++++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/test/tools/unified-spec-runner/match.ts b/test/tools/unified-spec-runner/match.ts index e12062bf85c..05c26495860 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) { expect(actualEvent).to.be.instanceOf(TopologyClosedEvent); const expectedSdamEvent = expectedEvent.topologyClosingEvent; 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..5cd670c34a5 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 as EventTopologyType, W } from '../../mongodb'; import { type TestConfiguration } from '../runner/config'; @@ -314,6 +315,7 @@ export interface ExpectedCmapEvent { connectionCheckedOutEvent?: Record; connectionCheckedInEvent?: Record; } + export interface ExpectedSdamEvent { serverDescriptionChangedEvent?: { previousDescription?: { @@ -336,10 +338,10 @@ export interface ExpectedSdamEvent { topologyDescriptionChangedEvent?: { topologyId?: any; previousDescription?: { - type?: string; + type?: EventTopologyType; }; newDescription?: { - type?: string; + type?: EventTopologyType; }; }; topologyOpeningEvent?: {