Skip to content

Commit 23dd6be

Browse files
committed
Reduce maxAwaitTimeMS in tests to cover MongoDB 6.0.
1 parent 7bdaaa0 commit 23dd6be

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

modules/module-mongodb/src/replication/ChangeStream.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ export interface ChangeStreamOptions {
2323
storage: storage.SyncRulesBucketStorage;
2424
metrics: MetricsEngine;
2525
abort_signal: AbortSignal;
26+
/**
27+
* Override maxAwaitTimeMS for testing.
28+
*
29+
* In most cases, the default of 10_000 is fine. However, for MongoDB 6.0, this can cause a delay
30+
* in closing the stream. To cover that case, reduce the timeout for tests.
31+
*/
32+
maxAwaitTimeMS?: number;
2633
}
2734

2835
interface InitResult {
@@ -56,6 +63,8 @@ export class ChangeStream {
5663
private readonly defaultDb: mongo.Db;
5764
private readonly metrics: MetricsEngine;
5865

66+
private readonly maxAwaitTimeMS: number;
67+
5968
private abort_signal: AbortSignal;
6069

6170
private relation_cache = new Map<string | number, storage.SourceTable>();
@@ -65,6 +74,7 @@ export class ChangeStream {
6574
this.metrics = options.metrics;
6675
this.group_id = options.storage.group_id;
6776
this.connections = options.connections;
77+
this.maxAwaitTimeMS = options.maxAwaitTimeMS ?? 10_000;
6878
this.client = this.connections.client;
6979
this.defaultDb = this.connections.db;
7080
this.sync_rules = options.storage.getParsedSyncRules({
@@ -557,7 +567,7 @@ export class ChangeStream {
557567

558568
const streamOptions: mongo.ChangeStreamOptions = {
559569
showExpandedEvents: true,
560-
maxAwaitTimeMS: 10_000,
570+
maxAwaitTimeMS: this.maxAwaitTimeMS,
561571
fullDocument: fullDocument
562572
};
563573

modules/module-mongodb/test/src/change_stream_utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ export class ChangeStreamTestContext {
8585
storage: this.storage,
8686
metrics: METRICS_HELPER.metricsEngine,
8787
connections: this.connectionManager,
88-
abort_signal: this.abortController.signal
88+
abort_signal: this.abortController.signal,
89+
// Specifically reduce this from the default for tests on MongoDB <= 6.0, otherwise it can take
90+
// a long time to abort the stream.
91+
maxAwaitTimeMS: 200
8992
};
9093
this._walStream = new ChangeStream(options);
9194
return this._walStream!;

0 commit comments

Comments
 (0)