Skip to content

Commit 9727233

Browse files
committed
wip run csot spec tests
1 parent 9ebf3dd commit 9727233

File tree

5 files changed

+50
-18
lines changed

5 files changed

+50
-18
lines changed

test/integration/client-side-operations-timeout/client_side_operations_timeout.spec.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { loadSpecTests } from '../../spec';
44
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
55

66
// TODO(NODE-5823): Implement unified runner operations and options support for CSOT
7-
describe.skip('CSOT spec tests', function () {
7+
describe('CSOT spec tests', function () {
88
runUnifiedSuite(loadSpecTests(join('client-side-operations-timeout')));
99
});

test/mongodb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ export * from '../src/sdam/topology';
201201
export * from '../src/sdam/topology_description';
202202
export * from '../src/sessions';
203203
export * from '../src/sort';
204+
export * from '../src/timeout';
204205
export * from '../src/transactions';
205206
export * from '../src/utils';
206207
export * from '../src/write_concern';

test/tools/unified-spec-runner/match.ts

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
ConnectionPoolCreatedEvent,
2121
ConnectionPoolReadyEvent,
2222
ConnectionReadyEvent,
23+
CSOTError,
2324
type Document,
2425
Long,
2526
MongoError,
@@ -134,7 +135,19 @@ export function isSpecialOperator(value: unknown): value is SpecialOperator {
134135

135136
const TYPE_MAP = new Map();
136137

137-
TYPE_MAP.set('double', actual => typeof actual === 'number' || actual._bsontype === 'Double');
138+
function hasBSONType(value: unknown): value is { _bsontype: string } & Record<string, any> {
139+
return (
140+
typeof value === 'object' &&
141+
value != null &&
142+
'_bsontype' in value &&
143+
typeof value._bsontype === 'string'
144+
);
145+
}
146+
147+
TYPE_MAP.set(
148+
'double',
149+
actual => typeof actual === 'number' || (hasBSONType(actual) && actual._bsontype === 'Double')
150+
);
138151
TYPE_MAP.set('string', actual => typeof actual === 'string');
139152
TYPE_MAP.set('object', actual => typeof actual === 'object' && actual !== null);
140153
TYPE_MAP.set('array', actual => Array.isArray(actual));
@@ -144,18 +157,26 @@ TYPE_MAP.set('objectId', actual => actual instanceof ObjectId);
144157
TYPE_MAP.set('bool', actual => typeof actual === 'boolean');
145158
TYPE_MAP.set('date', actual => actual instanceof Date);
146159
TYPE_MAP.set('null', actual => actual === null);
147-
TYPE_MAP.set('regex', actual => actual instanceof RegExp || actual._bsontype === 'BSONRegExp');
148-
TYPE_MAP.set('dbPointer', actual => actual._bsontype === 'DBRef');
149-
TYPE_MAP.set('javascript', actual => actual._bsontype === 'Code');
150-
TYPE_MAP.set('symbol', actual => actual._bsontype === 'Symbol');
151-
TYPE_MAP.set('javascriptWithScope', actual => actual._bsontype === 'Code' && actual.scope);
152-
TYPE_MAP.set('timestamp', actual => actual._bsontype === 'Timestamp');
153-
TYPE_MAP.set('decimal', actual => actual._bsontype === 'Decimal128');
154-
TYPE_MAP.set('minKey', actual => actual._bsontype === 'MinKey');
155-
TYPE_MAP.set('maxKey', actual => actual._bsontype === 'MaxKey');
160+
TYPE_MAP.set(
161+
'regex',
162+
actual => actual instanceof RegExp || (hasBSONType(actual) && actual._bsontype === 'BSONRegExp')
163+
);
164+
TYPE_MAP.set('dbPointer', actual => hasBSONType(actual) && actual._bsontype === 'DBRef');
165+
TYPE_MAP.set('javascript', actual => hasBSONType(actual) && actual._bsontype === 'Code');
166+
TYPE_MAP.set('symbol', actual => hasBSONType(actual) && actual._bsontype === 'Symbol');
167+
TYPE_MAP.set(
168+
'javascriptWithScope',
169+
actual => hasBSONType(actual) && actual._bsontype === 'Code' && actual.scope
170+
);
171+
TYPE_MAP.set('timestamp', actual => hasBSONType(actual) && actual._bsontype === 'Timestamp');
172+
TYPE_MAP.set('decimal', actual => hasBSONType(actual) && actual._bsontype === 'Decimal128');
173+
TYPE_MAP.set('minKey', actual => hasBSONType(actual) && actual._bsontype === 'MinKey');
174+
TYPE_MAP.set('maxKey', actual => hasBSONType(actual) && actual._bsontype === 'MaxKey');
156175
TYPE_MAP.set(
157176
'int',
158-
actual => (typeof actual === 'number' && Number.isInteger(actual)) || actual._bsontype === 'Int32'
177+
actual =>
178+
(typeof actual === 'number' && Number.isInteger(actual)) ||
179+
(hasBSONType(actual) && actual._bsontype === 'Int32')
159180
);
160181
TYPE_MAP.set(
161182
'long',
@@ -342,7 +363,7 @@ export function specialCheck(
342363
for (const type of types) {
343364
ok ||= TYPE_MAP.get(type)(actual);
344365
}
345-
expect(ok, `Expected [${actual}] to be one of [${types}]`).to.be.true;
366+
expect(ok, `Expected [${actual}] to be one of [${types}] at ${path.join('')}`).to.be.true;
346367
} else if (isExistsOperator(expected)) {
347368
// $$exists
348369
const actualExists = actual !== undefined && actual !== null;
@@ -728,6 +749,10 @@ export function expectErrorCheck(
728749
expect(error, expectMessage).to.be.instanceOf(MongoError);
729750
}
730751

752+
if (expected.isTimeoutError === true) {
753+
expect(CSOTError.is(error), error.stack).to.be.true;
754+
}
755+
731756
if (expected.isClientError === false) {
732757
expect(error).to.be.instanceOf(MongoServerError);
733758
} else if (expected.isClientError === true) {
@@ -741,19 +766,19 @@ export function expectErrorCheck(
741766
}
742767

743768
if (expected.errorCode != null) {
744-
expect(error, expectMessage).to.have.property('code', expected.errorCode);
769+
expect(error).to.have.property('code', expected.errorCode);
745770
}
746771

747772
if (expected.errorCodeName != null) {
748-
expect(error, expectMessage).to.have.property('codeName', expected.errorCodeName);
773+
expect(error).to.have.property('codeName', expected.errorCodeName);
749774
}
750775

751776
if (expected.errorLabelsContain != null) {
752777
const mongoError = error as MongoError;
753778
for (const errorLabel of expected.errorLabelsContain) {
754779
expect(
755780
mongoError.hasErrorLabel(errorLabel),
756-
`Error was supposed to have label ${errorLabel}, has [${mongoError.errorLabels}] -- ${expectMessage}`
781+
`Error was supposed to have label ${errorLabel}, has [${mongoError.errorLabels}]`
757782
).to.be.true;
758783
}
759784
}
@@ -763,7 +788,7 @@ export function expectErrorCheck(
763788
for (const errorLabel of expected.errorLabelsOmit) {
764789
expect(
765790
mongoError.hasErrorLabel(errorLabel),
766-
`Error was not supposed to have label ${errorLabel}, has [${mongoError.errorLabels}] -- ${expectMessage}`
791+
`Error was not supposed to have label ${errorLabel}, has [${mongoError.errorLabels}]`
767792
).to.be.false;
768793
}
769794
}

test/tools/unified-spec-runner/operations.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ operations.set('assertNumberConnectionsCheckedOut', async ({ entities, operation
198198
operations.set('bulkWrite', async ({ entities, operation }) => {
199199
const collection = entities.getEntity('collection', operation.object);
200200
const { requests, ...opts } = operation.arguments!;
201-
return collection.bulkWrite(requests, opts);
201+
const start = Math.trunc(performance.now());
202+
const res = await collection.bulkWrite(requests, opts);
203+
const end = Math.trunc(performance.now());
204+
205+
console.log(`bulkWrite took: ${end - start} ms`);
206+
return res;
202207
});
203208

204209
// The entity exists for the name but can potentially have the wrong

test/tools/unified-spec-runner/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ export interface StoreEventsAsEntity {
362362
export interface ExpectedError {
363363
isError?: true;
364364
isClientError?: boolean;
365+
isTimeoutError?: boolean;
365366
errorContains?: string;
366367
errorCode?: number;
367368
errorCodeName?: string;

0 commit comments

Comments
 (0)