Skip to content

Commit

Permalink
Merge branch 'main' into NODE-6090
Browse files Browse the repository at this point in the history
  • Loading branch information
W-A-James committed Apr 26, 2024
2 parents b9158a9 + 6d8ad33 commit 3b0eba4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
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
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
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
18 changes: 0 additions & 18 deletions test/unit/connection_string.spec.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { satisfies } from 'semver';

import { loadSpecTests } from '../spec';
import { executeUriValidationTest } from '../tools/uri_spec_runner';

Expand All @@ -11,22 +9,6 @@ const skipTests = [
describe('Connection String spec tests', function () {
const suites = loadSpecTests('connection-string');

beforeEach(function () {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const test = this.currentTest!;

const skippedTests = [
'Invalid port (zero) with IP literal',
'Invalid port (zero) with hostname'
];
test.skipReason =
satisfies(process.version, '>=20.0.0') && skippedTests.includes(test.title)
? 'TODO(NODE-5666): fix failing unit tests on Node20+'
: undefined;

if (test.skipReason) this.skip();
});

for (const suite of suites) {
describe(suite.name, function () {
for (const test of suite.tests) {
Expand Down

0 comments on commit 3b0eba4

Please sign in to comment.