Skip to content

Commit

Permalink
Merge pull request #227 from pelias/fix-stream-end
Browse files Browse the repository at this point in the history
fix(lookupStream): properly use lookupStream end event
  • Loading branch information
orangejulius committed Sep 6, 2018
2 parents 07486c7 + ef378b8 commit 5172ef6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lookupStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports = function(pipResolver, maxConcurrentReqs) {
const end = createPipResolverEnd(pipResolver);

const stream = parallelTransform(maxConcurrentReqs || 1, pipResolverStream);
stream.on('finish', end);
stream.on('end', end);

return stream;
};
19 changes: 17 additions & 2 deletions test/lookupStreamTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,31 @@ tape('tests', (test) => {
});

test.test('call end to stop child processes', (t) => {
// create a stubbed resolver that implements all required methods
const resolver = {
lookup: (centroid, search_layers, callback) => {
setTimeout(callback, 0, null, []);
},
end: function () {
t.assert(true, 'called end function');
t.equals(resolver, this, 'this is set to the correct object');
t.end();
}
};
// create one document to pass through the stream
const inputDoc = new Document( 'whosonfirst', 'placetype', '1')
.setCentroid({ lat: 12.121212, lon: 21.212121 });

stream(resolver).end();
// create the stream to test
const tested_stream = stream(resolver);

});
// consume the stream so that all data is processed
tested_stream.on('data', function() {});

// write document to stream
tested_stream.write(inputDoc, null, function() {});

// call end to trigger cleanup
tested_stream.end();
});
});

0 comments on commit 5172ef6

Please sign in to comment.