Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ 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: 'see NODE-5723' },
{ pattern: 'connect with serverMonitoringMode=stream >=4.4', reason: 'NODE-6045' },
{ pattern: 'connect with serverMonitoringMode=auto >=4.4', reason: 'NODE-6045' }
];

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;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -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"

28 changes: 15 additions & 13 deletions test/tools/unified-spec-runner/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
Expand Down
12 changes: 7 additions & 5 deletions test/tools/unified-spec-runner/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ServerApiVersion,
SeverityLevel,
TagSet,
TopologyType,
W
} from '../../mongodb';
import { type TestConfiguration } from '../runner/config';
Expand Down Expand Up @@ -95,15 +96,15 @@ export interface UnifiedSuite {
tests: Test[];
_yamlAnchors?: Document;
}
export const TopologyType = Object.freeze({
export const TopologyId = Object.freeze({
single: 'single',
replicaset: 'replicaset',
sharded: 'sharded',
shardedReplicaset: 'sharded-replicaset',
loadBalanced: 'load-balanced'
} as const);

export type TopologyId = (typeof TopologyType)[keyof typeof TopologyType];
export type TopologyId = (typeof TopologyId)[keyof typeof TopologyId];
export interface RunOnRequirement {
serverless?: 'forbid' | 'allow' | 'require';
auth?: boolean;
Expand Down Expand Up @@ -314,6 +315,7 @@ export interface ExpectedCmapEvent {
connectionCheckedOutEvent?: Record<string, never>;
connectionCheckedInEvent?: Record<string, never>;
}

export interface ExpectedSdamEvent {
serverDescriptionChangedEvent?: {
previousDescription?: {
Expand All @@ -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?: {
Expand Down