diff options
author | isaacs <i@izs.me> | 2013-04-08 22:00:26 +0400 |
---|---|---|
committer | Fedor Indutny <fedor.indutny@gmail.com> | 2013-04-09 02:09:51 +0400 |
commit | c93af860a079654becb3b1d06184ab7428dedffb (patch) | |
tree | 5a00aac479ff1764cd8d1b3c34dc0686f7107376 /test | |
parent | e4b716efaa00f34fe4d9f1c141c93e2aa994328c (diff) |
stream: call write cb before finish event
Since 049903e, an end callback could be called before a write
callback if end() is called before the write is done. This patch
resolves the issue.
In collaboration with @gne
Fixes felixge/node-formidable#209
Fixes #5215
Diffstat (limited to 'test')
-rw-r--r-- | test/simple/test-stream2-writable.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/simple/test-stream2-writable.js b/test/simple/test-stream2-writable.js index bdb7df2d04d..e0f384cb2ad 100644 --- a/test/simple/test-stream2-writable.js +++ b/test/simple/test-stream2-writable.js @@ -275,6 +275,18 @@ test('end callback after .write() call', function (t) { }); }); +test('end callback called after write callback', function (t) { + var tw = new TestWriter(); + var writeCalledback = false; + tw.write(new Buffer('hello world'), function() { + writeCalledback = true; + }); + tw.end(function () { + t.equal(writeCalledback, true); + t.end(); + }); +}); + test('encoding should be ignored for buffers', function(t) { var tw = new W(); var hex = '018b5e9a8f6236ffe30e31baf80d2cf6eb'; @@ -346,3 +358,20 @@ test('dont end while writing', function(t) { w.write(Buffer(0)); w.end(); }); + +test('finish does not come before write cb', function(t) { + var w = new W(); + var writeCb = false; + w._write = function(chunk, e, cb) { + setTimeout(function() { + writeCb = true; + cb(); + }, 10); + }; + w.on('finish', function() { + assert(writeCb); + t.end(); + }); + w.write(Buffer(0)); + w.end(); +}); |