Skip to content

Commit 0ac994a

Browse files
committed
Implement spec runner changes
1 parent 61564cd commit 0ac994a

File tree

7 files changed

+46
-5
lines changed

7 files changed

+46
-5
lines changed

src/cmap/connection_pool.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
388388
}
389389
} else {
390390
timeout = Timeout.expires(waitQueueTimeoutMS);
391+
clearTimeout = true;
391392
}
392393

393394
const waitQueueMember: WaitQueueMember = {

src/error.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,15 @@ export class MongoOperationTimeoutError extends MongoRuntimeError {
768768
}
769769
}
770770

771+
/**
772+
* @internal
773+
*/
774+
export class MongoOperationTimeoutError extends MongoRuntimeError {
775+
override get name(): string {
776+
return 'MongoOperationTimeoutError';
777+
}
778+
}
779+
771780
/**
772781
* An error thrown when the user attempts to add options to a cursor that has already been
773782
* initialized

src/operations/find.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ export class FindOperation extends CommandOperation<Document> {
112112
...this.options,
113113
...this.bsonOptions,
114114
documentsReturnedIn: 'firstBatch',
115-
session,
116-
timeout: this.timeout
115+
sessiontimeout: this.timeout
117116
},
118117
undefined
119118
);

src/operations/operation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ export abstract class AbstractOperation<TResult = any> {
6767
/** @internal */
6868
timeoutMS?: number;
6969

70+
/** @internal */
71+
serverSelectionTimeout?: Timeout;
72+
7073
[kSession]: ClientSession | undefined;
7174

7275
constructor(options: OperationOptions = {}) {

src/sdam/topology.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
565565
}
566566
const serverSelectionTimeoutMS = options.serverSelectionTimeoutMS ?? 0;
567567
let timeout: Timeout | null;
568+
568569
if (options.timeout) {
569570
// CSOT Enabled
570571
if (options.timeout.duration > 0 || serverSelectionTimeoutMS > 0) {
@@ -581,6 +582,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
581582
}
582583
} else {
583584
timeout = Timeout.expires(serverSelectionTimeoutMS);
585+
clearTimeout = true;
584586
}
585587

586588
const isSharded = this.description.type === TopologyType.Sharded;

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
type Document,
2424
Long,
2525
MongoError,
26+
MongoOperationTimeoutError,
2627
MongoServerError,
2728
ObjectId,
2829
type OneOrMore,
@@ -96,6 +97,19 @@ export function isMatchAsRootOperator(value: unknown): value is MatchAsRootOpera
9697
return typeof value === 'object' && value != null && '$$matchAsRoot' in value;
9798
}
9899

100+
export interface LteOperator {
101+
$$lte: number;
102+
}
103+
104+
export function isLteOperator(value: unknown): value is LteOperator {
105+
return (
106+
typeof value === 'object' &&
107+
value != null &&
108+
'$$lte' in value &&
109+
typeof value['$$lte'] === 'number'
110+
);
111+
}
112+
99113
export const SpecialOperatorKeys = [
100114
'$$exists',
101115
'$$type',
@@ -104,7 +118,8 @@ export const SpecialOperatorKeys = [
104118
'$$matchAsRoot',
105119
'$$matchAsDocument',
106120
'$$unsetOrMatches',
107-
'$$sessionLsid'
121+
'$$sessionLsid',
122+
'$$lte'
108123
];
109124

110125
export type SpecialOperator =
@@ -115,7 +130,8 @@ export type SpecialOperator =
115130
| UnsetOrMatchesOperator
116131
| SessionLsidOperator
117132
| MatchAsDocumentOperator
118-
| MatchAsRootOperator;
133+
| MatchAsRootOperator
134+
| LteOperator;
119135

120136
type KeysOfUnion<T> = T extends object ? keyof T : never;
121137
export type SpecialOperatorKey = KeysOfUnion<SpecialOperator>;
@@ -128,7 +144,8 @@ export function isSpecialOperator(value: unknown): value is SpecialOperator {
128144
isUnsetOrMatchesOperator(value) ||
129145
isSessionLsidOperator(value) ||
130146
isMatchAsRootOperator(value) ||
131-
isMatchAsDocumentOperator(value)
147+
isMatchAsDocumentOperator(value) ||
148+
isLteOperator(value)
132149
);
133150
}
134151

@@ -377,6 +394,9 @@ export function specialCheck(
377394
);
378395

379396
resultCheck(actual, expected.$$matchAsRoot as any, entities, path, false);
397+
} else if (isLteOperator(expected)) {
398+
expect(typeof actual).to.equal('number');
399+
expect(actual).to.be.lte(expected.$$lte);
380400
} else {
381401
expect.fail(`Unknown special operator: ${JSON.stringify(expected)}`);
382402
}
@@ -736,6 +756,12 @@ export function expectErrorCheck(
736756
expect(error).not.to.be.instanceOf(MongoServerError);
737757
}
738758

759+
if (expected.isTimeoutError === false) {
760+
expect(error).to.not.be.instanceof(MongoOperationTimeoutError);
761+
} else if (expected.isTimeoutError === true) {
762+
expect(error).to.be.instanceof(MongoOperationTimeoutError);
763+
}
764+
739765
if (expected.errorContains != null) {
740766
expect(error.message.toLowerCase(), expectMessage.toLowerCase()).to.include(
741767
expected.errorContains.toLowerCase()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ export interface StoreEventsAsEntity {
364364
}
365365
export interface ExpectedError {
366366
isError?: true;
367+
isTimeoutError?: boolean;
367368
isClientError?: boolean;
368369
errorContains?: string;
369370
errorCode?: number;

0 commit comments

Comments
 (0)