1
1
'use strict' ;
2
+ const path = require ( 'path' ) ;
2
3
const assert = require ( 'assert' ) ;
3
4
const Transform = require ( 'stream' ) . Transform ;
4
5
const MongoNetworkError = require ( '../../lib/core' ) . MongoNetworkError ;
@@ -1474,7 +1475,7 @@ describe('Change Streams', function() {
1474
1475
}
1475
1476
} ) ;
1476
1477
1477
- it . skip ( 'should resume piping of Change Streams when a resumable error is encountered' , {
1478
+ it ( 'should resume piping of Change Streams when a resumable error is encountered' , {
1478
1479
metadata : {
1479
1480
requires : {
1480
1481
generators : true ,
@@ -1483,14 +1484,13 @@ describe('Change Streams', function() {
1483
1484
}
1484
1485
} ,
1485
1486
test : function ( done ) {
1487
+ const filename = path . join ( __dirname , '_nodemongodbnative_resumepipe.txt' ) ;
1488
+ this . defer ( ( ) => fs . unlinkSync ( filename ) ) ;
1486
1489
const configuration = this . configuration ;
1487
1490
const ObjectId = configuration . require . ObjectId ;
1488
1491
const Timestamp = configuration . require . Timestamp ;
1489
1492
const Long = configuration . require . Long ;
1490
1493
1491
- // Contain mock server
1492
- let primaryServer = null ;
1493
-
1494
1494
// Default message fields
1495
1495
const defaultFields = {
1496
1496
setName : 'rs' ,
@@ -1506,9 +1506,8 @@ describe('Change Streams', function() {
1506
1506
hosts : [ 'localhost:32000' , 'localhost:32001' , 'localhost:32002' ]
1507
1507
} ;
1508
1508
1509
- co ( function * ( ) {
1510
- primaryServer = yield mock . createServer ( ) ;
1511
-
1509
+ mock . createServer ( 32000 , 'localhost' ) . then ( primaryServer => {
1510
+ this . defer ( ( ) => mock . cleanup ( ) ) ;
1512
1511
let counter = 0 ;
1513
1512
primaryServer . setMessageHandler ( request => {
1514
1513
const doc = request . document ;
@@ -1594,31 +1593,26 @@ describe('Change Streams', function() {
1594
1593
1595
1594
client . connect ( ( err , client ) => {
1596
1595
expect ( err ) . to . not . exist ;
1596
+ this . defer ( ( ) => client . close ( ) ) ;
1597
1597
1598
1598
const database = client . db ( 'integration_tests5' ) ;
1599
1599
const collection = database . collection ( 'MongoNetworkErrorTestPromises' ) ;
1600
1600
const changeStream = collection . watch ( pipeline ) ;
1601
1601
1602
- const filename = '/tmp/_nodemongodbnative_resumepipe.txt' ;
1603
1602
const outStream = fs . createWriteStream ( filename ) ;
1604
1603
1605
1604
changeStream . stream ( { transform : JSON . stringify } ) . pipe ( outStream ) ;
1606
-
1605
+ this . defer ( ( ) => changeStream . close ( ) ) ;
1607
1606
// Listen for changes to the file
1608
- const watcher = fs . watch ( filename , function ( eventType ) {
1609
- assert . equal ( eventType , 'change' ) ;
1607
+ const watcher = fs . watch ( filename , eventType => {
1608
+ this . defer ( ( ) => watcher . close ( ) ) ;
1609
+ expect ( eventType ) . to . equal ( 'change' ) ;
1610
1610
1611
1611
const fileContents = fs . readFileSync ( filename , 'utf8' ) ;
1612
1612
const parsedFileContents = JSON . parse ( fileContents ) ;
1613
- assert . equal ( parsedFileContents . fullDocument . a , 1 ) ;
1614
-
1615
- watcher . close ( ) ;
1613
+ expect ( parsedFileContents ) . to . have . nested . property ( 'fullDocument.a' , 1 ) ;
1616
1614
1617
- changeStream . close ( err => {
1618
- expect ( err ) . to . not . exist ;
1619
-
1620
- mock . cleanup ( ( ) => done ( ) ) ;
1621
- } ) ;
1615
+ done ( ) ;
1622
1616
} ) ;
1623
1617
} ) ;
1624
1618
} ) ;
0 commit comments