summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-05-08 12:54:29 -0700
committerisaacs <i@izs.me>2013-05-09 09:35:32 -0700
commitc38ce9bc0a143141abfa638289b458ddaaac26d6 (patch)
treeefefb8cb72226d3d19a08987075b19b49ce06c2e /test
parent8a407f58b96ca6c8a5d1542bde39ebb879eb307d (diff)
downloadandroid-node-v8-c38ce9bc0a143141abfa638289b458ddaaac26d6.tar.gz
android-node-v8-c38ce9bc0a143141abfa638289b458ddaaac26d6.tar.bz2
android-node-v8-c38ce9bc0a143141abfa638289b458ddaaac26d6.zip
stream: Guarantee ordering of 'finish' event
In synchronous Writable streams (where the _write cb is called on the current tick), the 'finish' event (and thus the end() callback) can in some cases be called before all the write() callbacks are called. Use a counter, and have stream.Transform rely on the 'prefinish' event instead of the 'finish' event. This has zero effect on most streams, but it corrects an edge case and makes it perform more deterministically, which is a Good Thing.
Diffstat (limited to 'test')
-rw-r--r--test/simple/test-stream2-writable.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/simple/test-stream2-writable.js b/test/simple/test-stream2-writable.js
index e0f384cb2a..704100c0da 100644
--- a/test/simple/test-stream2-writable.js
+++ b/test/simple/test-stream2-writable.js
@@ -375,3 +375,19 @@ test('finish does not come before write cb', function(t) {
w.write(Buffer(0));
w.end();
});
+
+test('finish does not come before sync _write cb', function(t) {
+ var w = new W();
+ var writeCb = false;
+ w._write = function(chunk, e, cb) {
+ cb();
+ };
+ w.on('finish', function() {
+ assert(writeCb);
+ t.end();
+ });
+ w.write(Buffer(0), function(er) {
+ writeCb = true;
+ });
+ w.end();
+});