@@ -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
2835interface 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
0 commit comments