1
1
'use strict' ;
2
+ const path = require ( 'path' ) ;
2
3
const assert = require ( 'assert' ) ;
3
4
const { Transform, PassThrough } = require ( 'stream' ) ;
4
5
const { MongoNetworkError } = require ( '../../src/error' ) ;
@@ -1454,8 +1455,7 @@ describe('Change Streams', function () {
1454
1455
}
1455
1456
} ) ;
1456
1457
1457
- // TODO: resuming currently broken on piped change streams, fix as part of NODE-2172
1458
- it . skip ( 'should resume piping of Change Streams when a resumable error is encountered' , {
1458
+ it ( 'should resume piping of Change Streams when a resumable error is encountered' , {
1459
1459
metadata : {
1460
1460
requires : {
1461
1461
generators : true ,
@@ -1464,11 +1464,10 @@ describe('Change Streams', function () {
1464
1464
}
1465
1465
} ,
1466
1466
test : function ( done ) {
1467
+ const filename = path . join ( __dirname , '_nodemongodbnative_resumepipe.txt' ) ;
1468
+ this . defer ( ( ) => fs . unlinkSync ( filename ) ) ;
1467
1469
const configuration = this . configuration ;
1468
1470
1469
- // Contain mock server
1470
- let primaryServer = null ;
1471
-
1472
1471
// Default message fields
1473
1472
const defaultFields = {
1474
1473
setName : 'rs' ,
@@ -1484,9 +1483,8 @@ describe('Change Streams', function () {
1484
1483
hosts : [ 'localhost:32000' , 'localhost:32001' , 'localhost:32002' ]
1485
1484
} ;
1486
1485
1487
- co ( function * ( ) {
1488
- primaryServer = yield mock . createServer ( ) ;
1489
-
1486
+ mock . createServer ( 32000 , 'localhost' ) . then ( primaryServer => {
1487
+ this . defer ( ( ) => mock . cleanup ( ) ) ;
1490
1488
let counter = 0 ;
1491
1489
primaryServer . setMessageHandler ( request => {
1492
1490
const doc = request . document ;
@@ -1572,31 +1570,26 @@ describe('Change Streams', function () {
1572
1570
1573
1571
client . connect ( ( err , client ) => {
1574
1572
expect ( err ) . to . not . exist ;
1573
+ this . defer ( ( ) => client . close ( ) ) ;
1575
1574
1576
1575
const database = client . db ( 'integration_tests5' ) ;
1577
1576
const collection = database . collection ( 'MongoNetworkErrorTestPromises' ) ;
1578
1577
const changeStream = collection . watch ( pipeline ) ;
1579
1578
1580
- const filename = '/tmp/_nodemongodbnative_resumepipe.txt' ;
1581
1579
const outStream = fs . createWriteStream ( filename ) ;
1582
1580
1583
1581
changeStream . stream ( { transform : JSON . stringify } ) . pipe ( outStream ) ;
1584
-
1582
+ this . defer ( ( ) => changeStream . close ( ) ) ;
1585
1583
// Listen for changes to the file
1586
- const watcher = fs . watch ( filename , function ( eventType ) {
1587
- assert . equal ( eventType , 'change' ) ;
1584
+ const watcher = fs . watch ( filename , eventType => {
1585
+ this . defer ( ( ) => watcher . close ( ) ) ;
1586
+ expect ( eventType ) . to . equal ( 'change' ) ;
1588
1587
1589
1588
const fileContents = fs . readFileSync ( filename , 'utf8' ) ;
1590
1589
const parsedFileContents = JSON . parse ( fileContents ) ;
1591
- assert . equal ( parsedFileContents . fullDocument . a , 1 ) ;
1592
-
1593
- watcher . close ( ) ;
1590
+ expect ( parsedFileContents ) . to . have . nested . property ( 'fullDocument.a' , 1 ) ;
1594
1591
1595
- changeStream . close ( err => {
1596
- expect ( err ) . to . not . exist ;
1597
-
1598
- mock . cleanup ( ( ) => done ( ) ) ;
1599
- } ) ;
1592
+ done ( ) ;
1600
1593
} ) ;
1601
1594
} ) ;
1602
1595
} ) ;
0 commit comments