@@ -1111,7 +1111,7 @@ describe('Change Streams', function () {
11111111 changeStream . next ( ( err , doc ) => {
11121112 expect ( err ) . to . exist ;
11131113 expect ( doc ) . to . not . exist ;
1114- expect ( err . message ) . to . equal ( 'ChangeStream is closed' ) ;
1114+ expect ( err ? .message ) . to . equal ( 'ChangeStream is closed' ) ;
11151115 changeStream . close ( ( ) => client . close ( done ) ) ;
11161116 } ) ;
11171117 } ) ;
@@ -1372,23 +1372,139 @@ describe('Change Streams', function () {
13721372 )
13731373 . run ( ) ;
13741374
1375+ UnifiedTestSuiteBuilder . describe ( 'entity.watch() server-side options' )
1376+ . runOnRequirement ( {
1377+ topologies : [ 'replicaset' , 'sharded-replicaset' , 'sharded' , 'load-balanced' ] ,
1378+ minServerVersion : '4.4.0'
1379+ } )
1380+ . createEntities ( [
1381+ { client : { id : 'client0' , observeEvents : [ 'commandStartedEvent' ] } } ,
1382+ { database : { id : 'db0' , client : 'client0' , databaseName : 'watchOpts' } } ,
1383+ { collection : { id : 'collection0' , database : 'db0' , collectionName : 'watchOpts' } }
1384+ ] )
1385+ . test (
1386+ TestBuilder . it (
1387+ 'should use maxAwaitTimeMS option to set maxTimeMS on getMore and should not set maxTimeMS on aggregate'
1388+ )
1389+ . operation ( {
1390+ object : 'collection0' ,
1391+ name : 'createChangeStream' ,
1392+ saveResultAsEntity : 'changeStreamOnClient' ,
1393+ arguments : { maxAwaitTimeMS : 5000 }
1394+ } )
1395+ . operation ( {
1396+ name : 'insertOne' ,
1397+ object : 'collection0' ,
1398+ arguments : { document : { a : 1 } } ,
1399+ ignoreResultAndError : true
1400+ } )
1401+ . operation ( {
1402+ object : 'changeStreamOnClient' ,
1403+ name : 'iterateUntilDocumentOrError' ,
1404+ ignoreResultAndError : true
1405+ } )
1406+ . expectEvents ( {
1407+ client : 'client0' ,
1408+ events : [
1409+ {
1410+ commandStartedEvent : {
1411+ commandName : 'aggregate' ,
1412+ command : { maxTimeMS : { $$exists : false } }
1413+ }
1414+ } ,
1415+ { commandStartedEvent : { commandName : 'insert' } } ,
1416+ { commandStartedEvent : { commandName : 'getMore' , command : { maxTimeMS : 5000 } } }
1417+ ]
1418+ } )
1419+ . toJSON ( )
1420+ )
1421+ . test (
1422+ TestBuilder . it (
1423+ 'should use maxTimeMS option to set maxTimeMS on aggregate and not set maxTimeMS on getMore'
1424+ )
1425+ . operation ( {
1426+ object : 'collection0' ,
1427+ name : 'createChangeStream' ,
1428+ saveResultAsEntity : 'changeStreamOnClient' ,
1429+ arguments : { maxTimeMS : 5000 }
1430+ } )
1431+ . operation ( {
1432+ name : 'insertOne' ,
1433+ object : 'collection0' ,
1434+ arguments : { document : { a : 1 } } ,
1435+ ignoreResultAndError : true
1436+ } )
1437+ . operation ( {
1438+ object : 'changeStreamOnClient' ,
1439+ name : 'iterateUntilDocumentOrError' ,
1440+ ignoreResultAndError : true
1441+ } )
1442+ . expectEvents ( {
1443+ client : 'client0' ,
1444+ ignoreExtraEvents : true , // Sharded clusters have extra getMores
1445+ events : [
1446+ { commandStartedEvent : { commandName : 'aggregate' , command : { maxTimeMS : 5000 } } } ,
1447+ { commandStartedEvent : { commandName : 'insert' } } ,
1448+ {
1449+ commandStartedEvent : {
1450+ commandName : 'getMore' ,
1451+ command : { maxTimeMS : { $$exists : false } }
1452+ }
1453+ }
1454+ ]
1455+ } )
1456+ . toJSON ( )
1457+ )
1458+ . test (
1459+ TestBuilder . it (
1460+ 'should use maxTimeMS option to set maxTimeMS on aggregate and maxAwaitTimeMS option to set maxTimeMS on getMore'
1461+ )
1462+ . operation ( {
1463+ object : 'collection0' ,
1464+ name : 'createChangeStream' ,
1465+ saveResultAsEntity : 'changeStreamOnClient' ,
1466+ arguments : { maxTimeMS : 5000 , maxAwaitTimeMS : 6000 }
1467+ } )
1468+ . operation ( {
1469+ name : 'insertOne' ,
1470+ object : 'collection0' ,
1471+ arguments : { document : { a : 1 } } ,
1472+ ignoreResultAndError : true
1473+ } )
1474+ . operation ( {
1475+ object : 'changeStreamOnClient' ,
1476+ name : 'iterateUntilDocumentOrError' ,
1477+ ignoreResultAndError : true
1478+ } )
1479+ . expectEvents ( {
1480+ client : 'client0' ,
1481+ ignoreExtraEvents : true , // Sharded clusters have extra getMores
1482+ events : [
1483+ { commandStartedEvent : { commandName : 'aggregate' , command : { maxTimeMS : 5000 } } } ,
1484+ { commandStartedEvent : { commandName : 'insert' } } ,
1485+ { commandStartedEvent : { commandName : 'getMore' , command : { maxTimeMS : 6000 } } }
1486+ ]
1487+ } )
1488+ . toJSON ( )
1489+ )
1490+ . run ( ) ;
1491+
13751492 describe ( 'BSON Options' , function ( ) {
13761493 let client : MongoClient ;
13771494 let db : Db ;
13781495 let collection : Collection ;
13791496 let cs : ChangeStream ;
1497+
13801498 beforeEach ( async function ( ) {
13811499 client = await this . configuration . newClient ( { monitorCommands : true } ) . connect ( ) ;
13821500 db = client . db ( 'db' ) ;
13831501 collection = await db . createCollection ( 'collection' ) ;
13841502 } ) ;
1503+
13851504 afterEach ( async function ( ) {
13861505 await db . dropCollection ( 'collection' ) ;
13871506 await cs . close ( ) ;
13881507 await client . close ( ) ;
1389- client = undefined ;
1390- db = undefined ;
1391- collection = undefined ;
13921508 } ) ;
13931509
13941510 context ( 'promoteLongs' , ( ) => {
@@ -1452,7 +1568,7 @@ describe('Change Streams', function () {
14521568 it ( 'does not send invalid options on the aggregate command' , {
14531569 metadata : { requires : { topology : '!single' } } ,
14541570 test : async function ( ) {
1455- const started = [ ] ;
1571+ const started : CommandStartedEvent [ ] = [ ] ;
14561572
14571573 client . on ( 'commandStarted' , filterForCommands ( [ 'aggregate' ] , started ) ) ;
14581574 const doc = { invalidBSONOption : true } ;
@@ -1473,7 +1589,7 @@ describe('Change Streams', function () {
14731589 it ( 'does not send invalid options on the getMore command' , {
14741590 metadata : { requires : { topology : '!single' } } ,
14751591 test : async function ( ) {
1476- const started = [ ] ;
1592+ const started : CommandStartedEvent [ ] = [ ] ;
14771593
14781594 client . on ( 'commandStarted' , filterForCommands ( [ 'aggregate' ] , started ) ) ;
14791595 const doc = { invalidBSONOption : true } ;
@@ -1503,7 +1619,7 @@ describe('ChangeStream resumability', function () {
15031619 const changeStreamResumeOptions : ChangeStreamOptions = {
15041620 fullDocument : 'updateLookup' ,
15051621 collation : { locale : 'en' , maxVariable : 'punct' } ,
1506- maxAwaitTimeMS : 20000 ,
1622+ maxAwaitTimeMS : 2000 ,
15071623 batchSize : 200
15081624 } ;
15091625
0 commit comments