Skip to content

Commit 60a12bc

Browse files
fix circular dependency
1 parent 2941719 commit 60a12bc

File tree

9 files changed

+207
-198
lines changed

9 files changed

+207
-198
lines changed

test/integration/change-streams/change_stream.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ import {
2323
type ResumeToken
2424
} from '../../mongodb';
2525
import * as mock from '../../tools/mongodb-mock/index';
26-
import { type FailPoint, sleep, TestBuilder, UnifiedTestSuiteBuilder } from '../../tools/utils';
26+
import {
27+
type FailPoint,
28+
sleep,
29+
TestBuilder,
30+
UnifiedTestSuiteBuilder
31+
} from '../../tools/unified_suite_builder';
2732
import { delay, filterForCommands } from '../shared';
2833

2934
const initIteratorMode = async (cs: ChangeStream) => {

test/integration/enumerate_collections.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestBuilder, UnifiedTestSuiteBuilder } from '../tools/utils';
1+
import { TestBuilder, UnifiedTestSuiteBuilder } from '../tools/unified_suite_builder';
22

33
describe('listCollections', () => {
44
UnifiedTestSuiteBuilder.describe('comment option')

test/integration/enumerate_databases.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import { once } from 'events';
33

44
import { type MongoClient, MongoServerError } from '../mongodb';
5-
import { TestBuilder, UnifiedTestSuiteBuilder } from '../tools/utils';
5+
import { TestBuilder, UnifiedTestSuiteBuilder } from '../tools/unified_suite_builder';
66

77
const metadata: MongoDBMetadataUI = {
88
requires: {

test/integration/enumerate_indexes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestBuilder, UnifiedTestSuiteBuilder } from '../tools/utils';
1+
import { TestBuilder, UnifiedTestSuiteBuilder } from '../tools/unified_suite_builder';
22

33
describe('listIndexes()', () => {
44
UnifiedTestSuiteBuilder.describe('comment option')

test/integration/node-specific/comment_with_falsy_values.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22

33
import { type Collection, type CommandStartedEvent, Long, type MongoClient } from '../../mongodb';
4-
import { TestBuilder, UnifiedTestSuiteBuilder } from '../../tools/utils';
4+
import { TestBuilder, UnifiedTestSuiteBuilder } from '../../tools/unified_suite_builder';
55

66
const falsyValues = [0, false, '', Long.ZERO, null, NaN] as const;
77
const falsyToString = (value: (typeof falsyValues)[number]) => {

test/integration/unified-test-format/unified_test_format.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { type FailPoint, TestBuilder, UnifiedTestSuiteBuilder } from '../../tools/utils';
1+
import {
2+
type FailPoint,
3+
TestBuilder,
4+
UnifiedTestSuiteBuilder
5+
} from '../../tools/unified_suite_builder';
26

37
describe('Unified Test Runner', () => {
48
UnifiedTestSuiteBuilder.describe('withTransaction error propagation')

test/tools/runner/flaky.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ import { expect } from 'chai';
33
import { alphabetically } from '../utils';
44

55
export const flakyTests = [
6-
'CSOT spec tests legacy timeouts behave correctly for retryable operations operation fails after two consecutive socket timeouts - aggregate on collection',
7-
'CSOT spec tests legacy timeouts behave correctly for retryable operations operation succeeds after one socket timeout - aggregate on collection',
8-
'CSOT spec tests operations ignore deprecated timeout options if timeoutMS is set socketTimeoutMS is ignored if timeoutMS is set - dropIndex on collection',
9-
'CSOT spec tests runCursorCommand Non-tailable cursor lifetime remaining timeoutMS applied to getMore if timeoutMode is unset',
10-
'CSOT spec tests timeoutMS behaves correctly for GridFS download operations timeoutMS applied to entire download, not individual parts',
116
'Change Streams should properly handle a changeStream event being processed mid-close when invoked with promises',
127
'Client Side Encryption (Unified) namedKMS-rewrapManyDataKey rewrap to azure:name1',
138
'Client Side Encryption (Unified) rewrapManyDataKey rewrap with new GCP KMS provider',
@@ -37,6 +32,11 @@ export const flakyTests = [
3732
'Client Side Encryption Prose Tests 16. Rewrap Case 1: Rewrap with separate ClientEncryption should rewrap data key from local to kmip',
3833
'Client Side Encryption Prose Tests 16. Rewrap Case 1: Rewrap with separate ClientEncryption should rewrap data key from local to local',
3934
'Client Side Encryption Prose Tests 16. Rewrap Case 2: RewrapManyDataKeyOpts.provider is not optional when provider field is missing raises an error',
35+
'CSOT spec tests legacy timeouts behave correctly for retryable operations operation fails after two consecutive socket timeouts - aggregate on collection',
36+
'CSOT spec tests legacy timeouts behave correctly for retryable operations operation succeeds after one socket timeout - aggregate on collection',
37+
'CSOT spec tests operations ignore deprecated timeout options if timeoutMS is set socketTimeoutMS is ignored if timeoutMS is set - dropIndex on collection',
38+
'CSOT spec tests runCursorCommand Non-tailable cursor lifetime remaining timeoutMS applied to getMore if timeoutMode is unset',
39+
'CSOT spec tests timeoutMS behaves correctly for GridFS download operations timeoutMS applied to entire download, not individual parts',
4040
'Retryable Reads (unified) retryable reads handshake failures collection.aggregate succeeds after retryable handshake network error',
4141
'Retryable Writes (unified) retryable writes handshake failures collection.updateOne succeeds after retryable handshake network error',
4242
'Server Discovery and Monitoring Prose Tests Connection Pool Management ensure monitors properly create and unpause connection pools when they discover servers',

test/tools/unified_suite_builder.ts

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
import { runUnifiedSuite } from './unified-spec-runner/runner';
2+
import {
3+
type CollectionData,
4+
type EntityDescription,
5+
type ExpectedEventsForClient,
6+
type OperationDescription,
7+
type RunOnRequirement,
8+
type Test,
9+
type UnifiedSuite
10+
} from './unified-spec-runner/schema';
11+
12+
export class TestBuilder {
13+
private _description: string;
14+
private runOnRequirements: RunOnRequirement[] = [];
15+
private _skipReason?: string;
16+
private _operations: OperationDescription[] = [];
17+
private _expectEvents?: ExpectedEventsForClient[] = [];
18+
private _outcome?: CollectionData[] = [];
19+
20+
static it(title: string) {
21+
return new TestBuilder(title);
22+
}
23+
24+
constructor(description: string) {
25+
this._description = description;
26+
}
27+
28+
operation(operation: OperationDescription): this {
29+
this._operations.push({
30+
object: 'collection0',
31+
arguments: {},
32+
...operation
33+
});
34+
return this;
35+
}
36+
37+
runOnRequirement(requirement: RunOnRequirement): this {
38+
this.runOnRequirements.push(requirement);
39+
return this;
40+
}
41+
42+
expectEvents(event: ExpectedEventsForClient): this {
43+
this._expectEvents.push(event);
44+
return this;
45+
}
46+
47+
toJSON(): Test {
48+
const test: Test = {
49+
description: this._description,
50+
runOnRequirements: this.runOnRequirements,
51+
operations: this._operations,
52+
expectEvents: this._expectEvents,
53+
outcome: this._outcome
54+
};
55+
56+
if (this._skipReason != null) {
57+
test.skipReason = this._skipReason;
58+
}
59+
60+
return test;
61+
}
62+
}
63+
64+
export class UnifiedTestSuiteBuilder {
65+
private _description = 'Default Description';
66+
private _schemaVersion = '1.0';
67+
private _createEntities: EntityDescription[];
68+
private _runOnRequirement: RunOnRequirement[] = [];
69+
private _initialData: CollectionData[] = [];
70+
private _tests: Test[] = [];
71+
72+
static describe(title: string) {
73+
return new UnifiedTestSuiteBuilder(title);
74+
}
75+
76+
/**
77+
* Establish common defaults
78+
* - id and name = client0, listens for commandStartedEvent
79+
* - id and name = database0
80+
* - id and name = collection0
81+
*/
82+
static get defaultEntities(): EntityDescription[] {
83+
return [
84+
{
85+
client: {
86+
id: 'client0',
87+
useMultipleMongoses: true,
88+
observeEvents: ['commandStartedEvent']
89+
}
90+
},
91+
{
92+
database: {
93+
id: 'database0',
94+
client: 'client0',
95+
databaseName: 'database0'
96+
}
97+
},
98+
{
99+
collection: {
100+
id: 'collection0',
101+
database: 'database0',
102+
collectionName: 'collection0'
103+
}
104+
}
105+
];
106+
}
107+
108+
constructor(description: string) {
109+
this._description = description;
110+
this._createEntities = [];
111+
}
112+
113+
description(description: string): this {
114+
this._description = description;
115+
return this;
116+
}
117+
118+
test(test: Test): this;
119+
test(test: Test[]): this;
120+
test(test: Test | Test[]): this {
121+
if (Array.isArray(test)) {
122+
this._tests.push(...test);
123+
} else {
124+
this._tests.push(test);
125+
}
126+
return this;
127+
}
128+
129+
createEntities(entity: EntityDescription): this;
130+
createEntities(entity: EntityDescription[]): this;
131+
createEntities(entity: EntityDescription | EntityDescription[]): this {
132+
if (Array.isArray(entity)) {
133+
this._createEntities.push(...entity);
134+
} else {
135+
this._createEntities.push(entity);
136+
}
137+
return this;
138+
}
139+
140+
initialData(data: CollectionData): this;
141+
initialData(data: CollectionData[]): this;
142+
initialData(data: CollectionData | CollectionData[]): this {
143+
if (Array.isArray(data)) {
144+
this._initialData.push(...data);
145+
} else {
146+
this._initialData.push(data);
147+
}
148+
return this;
149+
}
150+
151+
runOnRequirement(requirement: RunOnRequirement): this;
152+
runOnRequirement(requirement: RunOnRequirement[]): this;
153+
runOnRequirement(requirement: RunOnRequirement | RunOnRequirement[]): this {
154+
Array.isArray(requirement)
155+
? this._runOnRequirement.push(...requirement)
156+
: this._runOnRequirement.push(requirement);
157+
return this;
158+
}
159+
160+
schemaVersion(version: string): this {
161+
this._schemaVersion = version;
162+
return this;
163+
}
164+
165+
toJSON(): UnifiedSuite {
166+
return {
167+
description: this._description,
168+
schemaVersion: this._schemaVersion,
169+
runOnRequirements: this._runOnRequirement,
170+
createEntities: this._createEntities,
171+
initialData: this._initialData,
172+
tests: this._tests
173+
};
174+
}
175+
176+
run(): void {
177+
return runUnifiedSuite([this.toJSON()]);
178+
}
179+
180+
toMocha() {
181+
return describe(this._description, () => runUnifiedSuite([this.toJSON()]));
182+
}
183+
184+
clone(): UnifiedSuite {
185+
return JSON.parse(JSON.stringify(this));
186+
}
187+
}

0 commit comments

Comments
 (0)