Skip to content

Commit 7d023a6

Browse files
author
Thomas Reggi
authored
fix: correctly re-establishes pipe destinations (#2592)
reenable tests in master for reestablishing piped destinations after a change stream resumes NODE-2172
1 parent b4ec3ed commit 7d023a6

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

test/functional/change_stream.test.js

+13-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
const path = require('path');
23
const assert = require('assert');
34
const { Transform, PassThrough } = require('stream');
45
const { MongoNetworkError } = require('../../src/error');
@@ -1454,8 +1455,7 @@ describe('Change Streams', function () {
14541455
}
14551456
});
14561457

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', {
14591459
metadata: {
14601460
requires: {
14611461
generators: true,
@@ -1464,11 +1464,10 @@ describe('Change Streams', function () {
14641464
}
14651465
},
14661466
test: function (done) {
1467+
const filename = path.join(__dirname, '_nodemongodbnative_resumepipe.txt');
1468+
this.defer(() => fs.unlinkSync(filename));
14671469
const configuration = this.configuration;
14681470

1469-
// Contain mock server
1470-
let primaryServer = null;
1471-
14721471
// Default message fields
14731472
const defaultFields = {
14741473
setName: 'rs',
@@ -1484,9 +1483,8 @@ describe('Change Streams', function () {
14841483
hosts: ['localhost:32000', 'localhost:32001', 'localhost:32002']
14851484
};
14861485

1487-
co(function* () {
1488-
primaryServer = yield mock.createServer();
1489-
1486+
mock.createServer(32000, 'localhost').then(primaryServer => {
1487+
this.defer(() => mock.cleanup());
14901488
let counter = 0;
14911489
primaryServer.setMessageHandler(request => {
14921490
const doc = request.document;
@@ -1572,31 +1570,26 @@ describe('Change Streams', function () {
15721570

15731571
client.connect((err, client) => {
15741572
expect(err).to.not.exist;
1573+
this.defer(() => client.close());
15751574

15761575
const database = client.db('integration_tests5');
15771576
const collection = database.collection('MongoNetworkErrorTestPromises');
15781577
const changeStream = collection.watch(pipeline);
15791578

1580-
const filename = '/tmp/_nodemongodbnative_resumepipe.txt';
15811579
const outStream = fs.createWriteStream(filename);
15821580

15831581
changeStream.stream({ transform: JSON.stringify }).pipe(outStream);
1584-
1582+
this.defer(() => changeStream.close());
15851583
// 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');
15881587

15891588
const fileContents = fs.readFileSync(filename, 'utf8');
15901589
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);
15941591

1595-
changeStream.close(err => {
1596-
expect(err).to.not.exist;
1597-
1598-
mock.cleanup(() => done());
1599-
});
1592+
done();
16001593
});
16011594
});
16021595
});

0 commit comments

Comments
 (0)