Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(NODE-6052): support assertions on topologyDescriptionChanged in expectEvents #4089

Merged
merged 16 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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,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;
});
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) {
baileympearson marked this conversation as resolved.
Show resolved Hide resolved
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
14 changes: 8 additions & 6 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,21 +96,21 @@ export interface UnifiedSuite {
tests: Test[];
_yamlAnchors?: Document;
}
export const TopologyType = Object.freeze({
export const TopologyName = 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 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;
}
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
Loading