Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

New failing test: 'finish' firing before _flush is done in async case. #7612

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion test/simple/test-stream2-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ test('assymetric transform (expand)', function(t) {
});
});

test('assymetric transform (compress)', function(t) {
test('asymmetric transform (compress)', function(t) {
var pt = new Transform;

// each output is the first char of 3 consecutive chunks,
Expand Down Expand Up @@ -520,3 +520,39 @@ test('object transform (json stringify)', function(t) {
t.end();
})
});

test("_flush with async call should complete before 'finish' is triggered", function (t) {
var stream = new Transform();

var order = [];

// Nothing interesting here
stream._transform = function (chunk, enc, next) {
next();
};

// _flush makes an async call.
stream._flush = function (callback) {
order.push("Expecting 1st: starting flush");

return process.nextTick(function () {
order.push("Expecting 2nd: finishing flush");
callback();
});
};

stream.on('finish',function () {
order.push("Expecting 3rd: finish triggered after flush is done");

t.same(order,[
"Expecting 1st: starting flush",
"Expecting 2nd: finishing flush",
"Expecting 3rd: finish triggered after flush is done"
]);
t.end();

});

stream.end("chunk");

});