summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2013-05-13 11:13:39 -0700
committerBert Belder <bertbelder@gmail.com>2013-05-13 11:13:39 -0700
commitbdc58811693fd4454b5c99cbbbdaddbce3950f6f (patch)
tree982ab861e3dd1c941bb5ad0782840669a8c4caf1
parent8db693a87e324d2354d253990e3f75a149c029e3 (diff)
parent21bd45676390fd21ffa7c3cca91af4ad37ed3e5c (diff)
downloadnode-bdc58811693fd4454b5c99cbbbdaddbce3950f6f.tar.gz
Merge branch 'v0.10'
Conflicts: tools/test.py
-rw-r--r--README.md2
-rw-r--r--doc/about/index.html4
-rw-r--r--doc/api/child_process.markdown8
-rw-r--r--doc/api/stream.markdown4
-rw-r--r--doc/blog.html4
-rw-r--r--doc/blog/Uncategorized/version-0-6.md17
-rw-r--r--doc/changelog-foot.html2
-rw-r--r--doc/changelog-head.html2
-rw-r--r--doc/community/index.html6
-rw-r--r--doc/download/index.html4
-rw-r--r--doc/index.html4
-rw-r--r--doc/logos/index.html4
-rw-r--r--doc/template.html4
-rw-r--r--lib/_stream_readable.js3
-rw-r--r--lib/child_process.js9
-rw-r--r--test/pummel/test-net-many-clients.js11
-rw-r--r--test/simple/test-child-process-recv-handle.js85
-rw-r--r--test/simple/test-stream2-readable-wrap-empty.js43
-rw-r--r--test/simple/test-stream2-readable-wrap.js116
19 files changed, 242 insertions, 90 deletions
diff --git a/README.md b/README.md
index d3ffbd014..aa505e555 100644
--- a/README.md
+++ b/README.md
@@ -51,7 +51,7 @@ Resources for Newcomers
- [nodejs.org](http://nodejs.org/)
- [how to install node.js and npm (node package manager)](http://joyeur.com/2010/12/10/installing-node-and-npm/)
- [list of modules](https://github.com/joyent/node/wiki/modules)
- - [searching the npm registry](http://search.npmjs.org/)
+ - [searching the npm registry](http://npmjs.org/)
- [list of companies and projects using node](https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node)
- [node.js mailing list](http://groups.google.com/group/nodejs)
- irc chatroom, [#node.js on freenode.net](http://webchat.freenode.net?channels=node.js&uio=d4)
diff --git a/doc/about/index.html b/doc/about/index.html
index 43422a662..f1dea6b24 100644
--- a/doc/about/index.html
+++ b/doc/about/index.html
@@ -24,7 +24,7 @@
<li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download">Download</a></li>
<li><a href="/about/" class="about current">About</a></li>
- <li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li>
+ <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li>
@@ -116,7 +116,7 @@ console.log('Server running at http://127.0.0.1:1337/');</pre>
<li><a href="/">Node.js</a></li>
<li><a href="/#download">Download</a></li>
<li><a href="/about/">About</a></li>
- <li><a href="http://search.npmjs.org/">npm Registry</a></li>
+ <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li>
diff --git a/doc/api/child_process.markdown b/doc/api/child_process.markdown
index dade32356..85c9c8b8d 100644
--- a/doc/api/child_process.markdown
+++ b/doc/api/child_process.markdown
@@ -466,11 +466,6 @@ See also: `child_process.exec()` and `child_process.fork()`
* `command` {String} The command to run, with space-separated arguments
* `options` {Object}
* `cwd` {String} Current working directory of the child process
- * `stdio` {Array|String} Child's stdio configuration. (See above)
- Only stdin is configurable, anything else will lead to unpredictable
- results.
- * `customFds` {Array} **Deprecated** File descriptors for the child to use
- for stdio. (See above)
* `env` {Object} Environment key-value pairs
* `encoding` {String} (Default: 'utf8')
* `timeout` {Number} (Default: 0)
@@ -524,9 +519,6 @@ the child process is killed.
* `args` {Array} List of string arguments
* `options` {Object}
* `cwd` {String} Current working directory of the child process
- * `stdio` {Array|String} Child's stdio configuration. (See above)
- * `customFds` {Array} **Deprecated** File descriptors for the child to use
- for stdio. (See above)
* `env` {Object} Environment key-value pairs
* `encoding` {String} (Default: 'utf8')
* `timeout` {Number} (Default: 0)
diff --git a/doc/api/stream.markdown b/doc/api/stream.markdown
index dd2fde068..12bf26f31 100644
--- a/doc/api/stream.markdown
+++ b/doc/api/stream.markdown
@@ -549,6 +549,10 @@ Emitted when the stream's write queue empties and it's safe to write
without buffering again. Listen for it when `stream.write()` returns
`false`.
+### Event: 'error'
+
+Emitted if there was an error receiving data.
+
### Event: 'close'
Emitted when the underlying resource (for example, the backing file
diff --git a/doc/blog.html b/doc/blog.html
index 4aa9d8de3..f6d9cf805 100644
--- a/doc/blog.html
+++ b/doc/blog.html
@@ -86,7 +86,7 @@
<li><a href="http://nodejs.org/about/" class="about">About</a></li>
- <li><a href="http://search.npmjs.org/" class="npm">npm
+ <li><a href="http://npmjs.org/" class="npm">npm
Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs">Docs</a></li>
@@ -213,7 +213,7 @@
<li><a href="http://nodejs.org/">Node.js</a></li>
<li><a href="http://nodejs.org/download/">Download</a></li>
<li><a href="http://nodejs.org/about/">About</a></li>
- <li><a href="http://search.npmjs.org/">npm Registry</a></li>
+ <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="http://nodejs.org/community/">Community</a></li>
diff --git a/doc/blog/Uncategorized/version-0-6.md b/doc/blog/Uncategorized/version-0-6.md
index 8dd9719e7..5cde4c61e 100644
--- a/doc/blog/Uncategorized/version-0-6.md
+++ b/doc/blog/Uncategorized/version-0-6.md
@@ -5,8 +5,19 @@ status: publish
category: Uncategorized
slug: version-0-6
-Version 0.6.0 will be released next week. Please spend some time this week upgrading your code to v0.5.10. Report any API differences at <a href="https://github.com/joyent/node/wiki/API-changes-between-v0.4-and-v0.6">https://github.com/joyent/node/wiki/API-changes-between-v0.4-and-v0.6</a> or report a bug to us at <a href="http://github.com/joyent/node/issues">http://github.com/joyent/node/issues</a> if you hit problems.
+Version 0.6.0 will be released next week. Please spend some time this
+week upgrading your code to v0.5.10. Report any API differences at <a
+href="https://github.com/joyent/node/wiki/API-changes-between-v0.4-and-v0.6">https://github.com/joyent/node/wiki/API-changes-between-v0.4-and-v0.6</a>
+or report a bug to us at <a
+href="http://github.com/joyent/node/issues">http://github.com/joyent/node/issues</a>
+if you hit problems.
-The API changes between v0.4.12 and v0.5.10 are 99% cosmetic, minor, and easy to fix. Most people are able to migrate their code in 10 minutes. Don't fear.
+The API changes between v0.4.12 and v0.5.10 are 99% cosmetic, minor,
+and easy to fix. Most people are able to migrate their code in 10
+minutes. Don't fear.
-Once you've ported your code to v0.5.10 please help out by testing third party modules. Make bug reports. Encourage authors to publish new versions of their modules. Go through the list of modules at <a href="http://search.npmjs.org/">http://search.npmjs.org/</a> and try out random ones. This is especially encouraged of Windows users!
+Once you've ported your code to v0.5.10 please help out by testing
+third party modules. Make bug reports. Encourage authors to publish
+new versions of their modules. Go through the list of modules at <a
+href="http://npmjs.org/">http://npmjs.org/</a> and try out random
+ones. This is especially encouraged of Windows users!
diff --git a/doc/changelog-foot.html b/doc/changelog-foot.html
index 427359c80..ff760e7c0 100644
--- a/doc/changelog-foot.html
+++ b/doc/changelog-foot.html
@@ -7,7 +7,7 @@
<li><a href="/">Node.js</a></li>
<li><a href="/download/">Download</a></li>
<li><a href="/about/">About</a></li>
- <li><a href="http://search.npmjs.org/">npm Registry</a></li>
+ <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li>
diff --git a/doc/changelog-head.html b/doc/changelog-head.html
index fdab34026..946904d05 100644
--- a/doc/changelog-head.html
+++ b/doc/changelog-head.html
@@ -19,7 +19,7 @@
<li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download">Download</a></li>
<li><a href="/about/" class="about">About</a></li>
- <li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li>
+ <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs current">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li>
diff --git a/doc/community/index.html b/doc/community/index.html
index 42a414070..e47182d59 100644
--- a/doc/community/index.html
+++ b/doc/community/index.html
@@ -28,7 +28,7 @@
<li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download">Download</a></li>
<li><a href="/about/" class="about">About</a></li>
- <li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li>
+ <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community current">Community</a></li>
@@ -93,7 +93,7 @@
Projects, Applications, and Companies Using Node</a> or the
<a href="https://github.com/joyent/node/wiki/modules">very long
list of Node modules</a>, many of which are published in the
- <a href="http://search.npmjs.org/">npm registry</a>.
+ <a href="http://npmjs.org/">npm registry</a>.
</p>
</div>
</div>
@@ -223,7 +223,7 @@
<li><a href="/">Node.js</a></li>
<li><a href="/download/">Download</a></li>
<li><a href="/about/">About</a></li>
- <li><a href="http://search.npmjs.org/">npm Registry</a></li>
+ <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li>
diff --git a/doc/download/index.html b/doc/download/index.html
index a4559b620..c17f61bd3 100644
--- a/doc/download/index.html
+++ b/doc/download/index.html
@@ -24,7 +24,7 @@
<li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download current">Download</a></li>
<li><a href="/about/" class="about">About</a></li>
- <li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li>
+ <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li>
@@ -162,7 +162,7 @@
<li><a href="/">Node.js</a></li>
<li><a href="/download/">Download</a></li>
<li><a href="/about/">About</a></li>
- <li><a href="http://search.npmjs.org/">npm Registry</a></li>
+ <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li>
diff --git a/doc/index.html b/doc/index.html
index 65f200910..586ada181 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -118,7 +118,7 @@ server.listen(1337, '127.0.0.1');</pre>
<h2>Explore Node.js</h2>
<ul id="explore">
<li><a href="about/" class="explore">About</a><br><span>Technical overview</span></li>
- <li><a href="http://search.npmjs.org/" class="explore">npm Registry</a><br><span>Modules, resources and more</span></li>
+ <li><a href="http://npmjs.org/" class="explore">npm Registry</a><br><span>Modules, resources and more</span></li>
<li><a href="http://nodejs.org/api/" class="explore">Documentation</a><br><span>API Specifications</span></li>
<li><a href="http://blog.nodejs.org" class="explore">Node.js Blog</a><br><span>Insight, perspective and events</span></li>
<li><a href="community/" class="explore">Community</a><br><span>Mailing lists, blogs, and more</span></li>
@@ -134,7 +134,7 @@ server.listen(1337, '127.0.0.1');</pre>
<li><a href="/">Node.js</a></li>
<li><a href="/download/">Download</a></li>
<li><a href="/about/">About</a></li>
- <li><a href="http://search.npmjs.org/">npm Registry</a></li>
+ <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li>
diff --git a/doc/logos/index.html b/doc/logos/index.html
index c07d4c7dd..be0559252 100644
--- a/doc/logos/index.html
+++ b/doc/logos/index.html
@@ -24,7 +24,7 @@
<li><a href="/" class="home">Home</a></li>
<li><a href="/#download" class="download">Download</a></li>
<li><a href="/about/" class="about">About</a></li>
- <li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li>
+ <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li>
@@ -68,7 +68,7 @@
<li><a href="/">Node.js</a></li>
<li><a href="/#download">Download</a></li>
<li><a href="/about/">About</a></li>
- <li><a href="http://search.npmjs.org/">npm Registry</a></li>
+ <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li>
diff --git a/doc/template.html b/doc/template.html
index 709c8e823..7c40bede9 100644
--- a/doc/template.html
+++ b/doc/template.html
@@ -19,7 +19,7 @@
<li><a href="/" class="home">Home</a></li>
<li><a href="/download/" class="download">Download</a></li>
<li><a href="/about/" class="about">About</a></li>
- <li><a href="http://search.npmjs.org/" class="npm">npm Registry</a></li>
+ <li><a href="http://npmjs.org/" class="npm">npm Registry</a></li>
<li><a href="http://nodejs.org/api/" class="docs current">Docs</a></li>
<li><a href="http://blog.nodejs.org" class="blog">Blog</a></li>
<li><a href="/community/" class="community">Community</a></li>
@@ -58,7 +58,7 @@
<li><a href="/">Node.js</a></li>
<li><a href="/download/">Download</a></li>
<li><a href="/about/">About</a></li>
- <li><a href="http://search.npmjs.org/">npm Registry</a></li>
+ <li><a href="http://npmjs.org/">npm Registry</a></li>
<li><a href="http://nodejs.org/api/">Docs</a></li>
<li><a href="http://blog.nodejs.org">Blog</a></li>
<li><a href="/community/">Community</a></li>
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 070628288..07bd8b046 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -759,7 +759,6 @@ Readable.prototype.wrap = function(stream) {
if (chunk && chunk.length)
self.push(chunk);
}
- state.ended = true;
self.push(null);
});
@@ -767,7 +766,7 @@ Readable.prototype.wrap = function(stream) {
stream.on('data', function(chunk) {
if (state.decoder)
chunk = state.decoder.write(chunk);
- if (!chunk || !chunk.length)
+ if (!chunk || !state.objectMode && !chunk.length)
return;
var ret = self.push(chunk);
diff --git a/lib/child_process.js b/lib/child_process.js
index 1b6b8b21d..f7312215c 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -336,8 +336,13 @@ function setupChannel(target, channel) {
var json = jsonBuffer.slice(start, i);
var message = JSON.parse(json);
- handleMessage(target, message, recvHandle);
- recvHandle = undefined;
+ // There will be at most one NODE_HANDLE message in every chunk we
+ // read because SCM_RIGHTS messages don't get coalesced. Make sure
+ // that we deliver the handle with the right message however.
+ if (message && message.cmd === 'NODE_HANDLE')
+ handleMessage(target, message, recvHandle);
+ else
+ handleMessage(target, message, undefined);
start = i + 1;
}
diff --git a/test/pummel/test-net-many-clients.js b/test/pummel/test-net-many-clients.js
index 3f394b8ab..83ff18199 100644
--- a/test/pummel/test-net-many-clients.js
+++ b/test/pummel/test-net-many-clients.js
@@ -37,12 +37,11 @@ for (var i = 0; i < bytes; i++) {
}
var server = net.createServer(function(c) {
- c.on('connect', function() {
- total_connections++;
- common.print('#');
- c.write(body);
- c.end();
- });
+ console.log('connected');
+ total_connections++;
+ common.print('#');
+ c.write(body);
+ c.end();
});
function runClient(callback) {
diff --git a/test/simple/test-child-process-recv-handle.js b/test/simple/test-child-process-recv-handle.js
new file mode 100644
index 000000000..dce5bdcba
--- /dev/null
+++ b/test/simple/test-child-process-recv-handle.js
@@ -0,0 +1,85 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// Test that a Linux specific quirk in the handle passing protocol is handled
+// correctly. See https://github.com/joyent/node/issues/5330 for details.
+
+var common = require('../common');
+var assert = require('assert');
+var net = require('net');
+var spawn = require('child_process').spawn;
+
+if (process.argv[2] === 'worker')
+ worker();
+else
+ master();
+
+function master() {
+ // spawn() can only create one IPC channel so we use stdin/stdout as an
+ // ad-hoc command channel.
+ var proc = spawn(process.execPath, [__filename, 'worker'], {
+ stdio: ['pipe', 'pipe', 'pipe', 'ipc']
+ });
+ var handle = null;
+ proc.on('exit', function() {
+ handle.close();
+ });
+ proc.stdout.on('data', function(data) {
+ assert.equal(data, 'ok\r\n');
+ net.createServer(assert.fail).listen(common.PORT, function() {
+ handle = this._handle;
+ proc.send('one');
+ proc.send('two', handle);
+ proc.send('three');
+ proc.stdin.write('ok\r\n');
+ });
+ });
+ proc.stderr.pipe(process.stderr);
+}
+
+function worker() {
+ process._channel.readStop(); // Make messages batch up.
+ process.stdout.ref();
+ process.stdout.write('ok\r\n');
+ process.stdin.once('data', function(data) {
+ assert.equal(data, 'ok\r\n');
+ process._channel.readStart();
+ });
+ var n = 0;
+ process.on('message', function(msg, handle) {
+ n += 1;
+ if (n === 1) {
+ assert.equal(msg, 'one');
+ assert.equal(handle, undefined);
+ }
+ else if (n === 2) {
+ assert.equal(msg, 'two');
+ assert.equal(typeof handle, 'object'); // Also matches null, therefore...
+ assert.ok(handle); // also check that it's truthy.
+ handle.close();
+ }
+ else if (n === 3) {
+ assert.equal(msg, 'three');
+ assert.equal(handle, undefined);
+ process.exit();
+ }
+ });
+}
diff --git a/test/simple/test-stream2-readable-wrap-empty.js b/test/simple/test-stream2-readable-wrap-empty.js
new file mode 100644
index 000000000..c7042f1b1
--- /dev/null
+++ b/test/simple/test-stream2-readable-wrap-empty.js
@@ -0,0 +1,43 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+
+var Readable = require('_stream_readable');
+var EE = require('events').EventEmitter;
+
+var oldStream = new EE();
+oldStream.pause = function(){};
+oldStream.resume = function(){};
+
+var newStream = new Readable().wrap(oldStream);
+
+var ended = false;
+newStream
+ .on('readable', function(){})
+ .on('end', function(){ ended = true; });
+
+oldStream.emit('end');
+
+process.on('exit', function(){
+ assert.ok(ended);
+}); \ No newline at end of file
diff --git a/test/simple/test-stream2-readable-wrap.js b/test/simple/test-stream2-readable-wrap.js
index 5fa5d185b..6b272be46 100644
--- a/test/simple/test-stream2-readable-wrap.js
+++ b/test/simple/test-stream2-readable-wrap.js
@@ -26,69 +26,83 @@ var Readable = require('_stream_readable');
var Writable = require('_stream_writable');
var EE = require('events').EventEmitter;
-var old = new EE;
-var r = new Readable({ highWaterMark: 10 });
-assert.equal(r, r.wrap(old));
+var testRuns = 0, completedRuns = 0;
+function runTest(highWaterMark, objectMode, produce) {
+ testRuns++;
-var ended = false;
-r.on('end', function() {
- ended = true;
-});
+ var old = new EE;
+ var r = new Readable({ highWaterMark: highWaterMark, objectMode: objectMode });
+ assert.equal(r, r.wrap(old));
-var pauses = 0;
-var resumes = 0;
+ var ended = false;
+ r.on('end', function() {
+ ended = true;
+ });
-old.pause = function() {
- pauses++;
- old.emit('pause');
- flowing = false;
-};
+ var pauses = 0;
+ var resumes = 0;
-old.resume = function() {
- resumes++;
- old.emit('resume');
- flow();
-};
-
-var flowing;
-var chunks = 10;
-var oldEnded = false;
-function flow() {
- flowing = true;
- while (flowing && chunks-- > 0) {
- old.emit('data', new Buffer('xxxxxxxxxx'));
- }
- if (chunks <= 0) {
- oldEnded = true;
- old.emit('end');
+ old.pause = function() {
+ pauses++;
+ old.emit('pause');
+ flowing = false;
+ };
+
+ old.resume = function() {
+ resumes++;
+ old.emit('resume');
+ flow();
+ };
+
+ var flowing;
+ var chunks = 10;
+ var oldEnded = false;
+ var expected = [];
+ function flow() {
+ flowing = true;
+ while (flowing && chunks-- > 0) {
+ var item = produce();
+ expected.push(item);
+ console.log('emit', chunks);
+ old.emit('data', item);
+ }
+ if (chunks <= 0) {
+ oldEnded = true;
+ console.log('old end', chunks, flowing);
+ old.emit('end');
+ }
}
-}
-var w = new Writable({ highWaterMark: 20 });
-var written = [];
-w._write = function(chunk, encoding, cb) {
- written.push(chunk.toString());
- setTimeout(cb);
-};
+ var w = new Writable({ highWaterMark: highWaterMark * 2, objectMode: objectMode });
+ var written = [];
+ w._write = function(chunk, encoding, cb) {
+ console.log(chunk);
+ written.push(chunk);
+ setTimeout(cb);
+ };
-var finished = false;
-w.on('finish', function() {
- finished = true;
-});
+ w.on('finish', function() {
+ completedRuns++;
+ performAsserts();
+ });
+ r.pipe(w);
-var expect = new Array(11).join('xxxxxxxxxx');
+ flow();
-r.pipe(w);
+ function performAsserts() {
+ assert(ended);
+ assert(oldEnded);
+ assert.deepEqual(written, expected);
+ assert.equal(pauses, 10);
+ assert.equal(resumes, 9);
+ }
+}
-flow();
+runTest(10, false, function(){ return new Buffer('xxxxxxxxxx'); });
+runTest(1, true, function(){ return { foo: 'bar' }; });
process.on('exit', function() {
- assert.equal(pauses, 10);
- assert.equal(resumes, 9);
- assert(ended);
- assert(finished);
- assert(oldEnded);
- assert.equal(written.join(''), expect);
+ assert.equal(testRuns, completedRuns);
console.log('ok');
});