@@ -1111,7 +1111,7 @@ describe('Change Streams', function () {
1111
1111
changeStream . next ( ( err , doc ) => {
1112
1112
expect ( err ) . to . exist ;
1113
1113
expect ( doc ) . to . not . exist ;
1114
- expect ( err . message ) . to . equal ( 'ChangeStream is closed' ) ;
1114
+ expect ( err ? .message ) . to . equal ( 'ChangeStream is closed' ) ;
1115
1115
changeStream . close ( ( ) => client . close ( done ) ) ;
1116
1116
} ) ;
1117
1117
} ) ;
@@ -1372,23 +1372,139 @@ describe('Change Streams', function () {
1372
1372
)
1373
1373
. run ( ) ;
1374
1374
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
+
1375
1492
describe ( 'BSON Options' , function ( ) {
1376
1493
let client : MongoClient ;
1377
1494
let db : Db ;
1378
1495
let collection : Collection ;
1379
1496
let cs : ChangeStream ;
1497
+
1380
1498
beforeEach ( async function ( ) {
1381
1499
client = await this . configuration . newClient ( { monitorCommands : true } ) . connect ( ) ;
1382
1500
db = client . db ( 'db' ) ;
1383
1501
collection = await db . createCollection ( 'collection' ) ;
1384
1502
} ) ;
1503
+
1385
1504
afterEach ( async function ( ) {
1386
1505
await db . dropCollection ( 'collection' ) ;
1387
1506
await cs . close ( ) ;
1388
1507
await client . close ( ) ;
1389
- client = undefined ;
1390
- db = undefined ;
1391
- collection = undefined ;
1392
1508
} ) ;
1393
1509
1394
1510
context ( 'promoteLongs' , ( ) => {
@@ -1452,7 +1568,7 @@ describe('Change Streams', function () {
1452
1568
it ( 'does not send invalid options on the aggregate command' , {
1453
1569
metadata : { requires : { topology : '!single' } } ,
1454
1570
test : async function ( ) {
1455
- const started = [ ] ;
1571
+ const started : CommandStartedEvent [ ] = [ ] ;
1456
1572
1457
1573
client . on ( 'commandStarted' , filterForCommands ( [ 'aggregate' ] , started ) ) ;
1458
1574
const doc = { invalidBSONOption : true } ;
@@ -1473,7 +1589,7 @@ describe('Change Streams', function () {
1473
1589
it ( 'does not send invalid options on the getMore command' , {
1474
1590
metadata : { requires : { topology : '!single' } } ,
1475
1591
test : async function ( ) {
1476
- const started = [ ] ;
1592
+ const started : CommandStartedEvent [ ] = [ ] ;
1477
1593
1478
1594
client . on ( 'commandStarted' , filterForCommands ( [ 'aggregate' ] , started ) ) ;
1479
1595
const doc = { invalidBSONOption : true } ;
@@ -1503,7 +1619,7 @@ describe('ChangeStream resumability', function () {
1503
1619
const changeStreamResumeOptions : ChangeStreamOptions = {
1504
1620
fullDocument : 'updateLookup' ,
1505
1621
collation : { locale : 'en' , maxVariable : 'punct' } ,
1506
- maxAwaitTimeMS : 20000 ,
1622
+ maxAwaitTimeMS : 2000 ,
1507
1623
batchSize : 200
1508
1624
} ;
1509
1625
0 commit comments