Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-11-21 07:49:44 +0300
committerRyan Dahl <ry@tinyclouds.org>2010-11-21 07:55:15 +0300
commit23204979926a3f69144be182786c5d2dcf58c0c2 (patch)
tree3336aefc4b3e0395f6e8718714a2480aa0b81716 /test
parent794e7be4f8f2a4e4b99599fe743421d04b3268fc (diff)
Revert "Merge branch 'writev'"
This reverts commit cd9515efd99dfa6510e72342a2621bb4b291a89c, reversing changes made to df46c8e698b9400abaabd77ec836c7cdadf9735c. Too slow. Needs more work.
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/recvfd.js16
-rw-r--r--test/simple/test-dumper-unix.js135
-rw-r--r--test/simple/test-dumper.js128
-rw-r--r--test/simple/test-pipe.js13
-rw-r--r--test/simple/test-sendfd.js17
5 files changed, 21 insertions, 288 deletions
diff --git a/test/fixtures/recvfd.js b/test/fixtures/recvfd.js
index 8f064693895..09b2864b7ed 100644
--- a/test/fixtures/recvfd.js
+++ b/test/fixtures/recvfd.js
@@ -22,33 +22,35 @@ function processData(s) {
// version of our modified object back. Clean up when we're done.
var pipeStream = new net.Stream(fd);
- pipeStream.resume();
-
- pipeStream.write(JSON.stringify(d) + '\n', function () {
+ var drainFunc = function() {
pipeStream.destroy();
if (++numSentMessages == 2) {
s.destroy();
}
- });
+ };
+
+ pipeStream.addListener('drain', drainFunc);
+ pipeStream.resume();
+
+ if (pipeStream.write(JSON.stringify(d) + '\n')) {
+ drainFunc();
+ }
};
// Create a UNIX socket to the path defined by argv[2] and read a file
// descriptor and misc data from it.
var s = new net.Stream();
-
s.addListener('fd', function(fd) {
receivedFDs.unshift(fd);
processData(s);
});
-
s.addListener('data', function(data) {
data.toString('utf8').trim().split('\n').forEach(function(d) {
receivedData.unshift(JSON.parse(d));
});
processData(s);
});
-
s.connect(process.argv[2]);
// vim:ts=2 sw=2 et
diff --git a/test/simple/test-dumper-unix.js b/test/simple/test-dumper-unix.js
deleted file mode 100644
index 2e510360d56..00000000000
--- a/test/simple/test-dumper-unix.js
+++ /dev/null
@@ -1,135 +0,0 @@
-var assert =require('assert');
-var IOWatcher = process.binding('io_watcher').IOWatcher;
-var errnoException = process.binding('net').errnoException;
-var close = process.binding('net').close;
-var net = require('net');
-
-var ncomplete = 0;
-
-function test (N, b, cb) {
- var fdsSent = 0;
- var fdsRecv = 0;
- //console.trace();
- var expected = N * b.length;
- var nread = 0;
-
- // Create a socketpair
- var fds = process.binding('net').socketpair();
-
- // Use writev/dumper to send data down the one of the sockets, fds[1].
- // This requires a IOWatcher.
- var w = new IOWatcher();
- w.set(fds[1], false, true);
- w.isUnixSocket = true;
-
- w.callback = function (readable, writable) {
- assert.ok(!readable && writable); // not really important.
- // Insert watcher into dumpQueue
- w.next = IOWatcher.dumpQueue.next;
- IOWatcher.dumpQueue.next = w;
- }
-
- var ndrain = 0;
- w.ondrain = function () {
- ndrain++;
- }
-
- var nerror = 0;
- w.onerror = function (errno) {
- throw errnoException(errno);
- nerror++;
- }
-
- // The read end, fds[0], will be used to count how much comes through.
- // This sets up a readable stream on fds[0].
- var stream = new net.Stream({ fd: fds[0], type: 'unix' });
- //stream.readable = true;
- stream.resume();
-
- stream.on('fd', function (fd) {
- console.log('got fd %d', fd);
- fdsRecv++;
- });
-
- // Count the data as it arrives on the other end
- stream.on('data', function (d) {
- nread += d.length;
-
- if (nread >= expected) {
- assert.ok(nread === expected);
- assert.equal(1, ndrain);
- assert.equal(0, nerror);
- console.error("done. wrote %d bytes\n", nread);
- close(fds[1]);
- }
- });
-
-
- stream.on('close', function () {
- assert.equal(fdsSent, fdsRecv);
- // check to make sure the watcher isn't in the dump queue.
- for (var x = IOWatcher.dumpQueue; x; x = x.next) {
- assert.ok(x !== w);
- }
- assert.equal(null, w.next);
- // completely flushed
- assert.ok(!w.firstBucket);
- assert.ok(!w.lastBucket);
-
- ncomplete++;
- if (cb) cb();
- });
-
-
- // Insert watcher into dumpQueue
- w.next = IOWatcher.dumpQueue.next;
- IOWatcher.dumpQueue.next = w;
-
- w.firstBucket = { data: b };
- w.lastBucket = w.firstBucket;
- w.queueSize = b.length;
-
- for (var i = 0; i < N-1; i++) {
- var bucket = { data: b };
- w.lastBucket.next = bucket;
- w.lastBucket = bucket;
- w.queueSize += b.length;
- // Kind of randomly fill these buckets with fds.
- if (fdsSent < 5 && i % 2 == 0) {
- bucket.fd = 1; // send stdout
- fdsSent++;
- }
- }
-}
-
-
-function runTests (values) {
- expectedToComplete = values.length;
-
- function go () {
- if (ncomplete < values.length) {
- var v = values[ncomplete];
- console.log("test N=%d, size=%d", v[0], v[1].length);
- test(v[0], v[1], go);
- }
- }
-
- go();
-}
-
-runTests([ [30, Buffer(1000)]
- , [4, Buffer(10000)]
- , [1, "hello world\n"]
- , [50, Buffer(1024*1024)]
- , [500, Buffer(40960+1)]
- , [500, Buffer(40960-1)]
- , [500, Buffer(40960)]
- , [500, Buffer(1024*1024+1)]
- , [50000, "hello world\n"]
- ]);
-
-
-process.on('exit', function () {
- assert.equal(expectedToComplete, ncomplete);
-});
-
diff --git a/test/simple/test-dumper.js b/test/simple/test-dumper.js
deleted file mode 100644
index c1597749f37..00000000000
--- a/test/simple/test-dumper.js
+++ /dev/null
@@ -1,128 +0,0 @@
-var assert =require('assert');
-var IOWatcher = process.binding('io_watcher').IOWatcher;
-var errnoException = process.binding('net').errnoException;
-var close = process.binding('net').close;
-var net = require('net');
-
-var ncomplete = 0;
-
-
-
-
-
-function test (N, b, cb) {
- //console.trace();
- var expected = N * b.length;
- var nread = 0;
-
- // Create a pipe
- var fds = process.binding('net').pipe();
- console.log("fds == %j", fds);
-
- // Use writev/dumper to send data down the write end of the pipe, fds[1].
- // This requires a IOWatcher.
- var w = new IOWatcher();
- w.set(fds[1], false, true);
-
- w.callback = function (readable, writable) {
- assert.ok(!readable && writable); // not really important.
- // Insert watcher into dumpQueue
- w.next = IOWatcher.dumpQueue.next;
- IOWatcher.dumpQueue.next = w;
- }
-
- var ndrain = 0;
- w.ondrain = function () {
- ndrain++;
- }
-
- var nerror = 0;
- w.onerror = function (errno) {
- throw errnoException(errno);
- nerror++;
- }
-
- // The read end, fds[0], will be used to count how much comes through.
- // This sets up a readable stream on fds[0].
- var stream = new net.Stream();
- stream.open(fds[0]);
- stream.readable = true;
- stream.resume();
-
- // Count the data as it arrives on the read end of the pipe.
- stream.on('data', function (d) {
- nread += d.length;
-
- if (nread >= expected) {
- assert.ok(nread === expected);
- assert.equal(1, ndrain);
- assert.equal(0, nerror);
- console.error("done. wrote %d bytes\n", nread);
- close(fds[1]);
- }
- });
-
- stream.on('close', function () {
- // check to make sure the watcher isn't in the dump queue.
- for (var x = IOWatcher.dumpQueue; x; x = x.next) {
- assert.ok(x !== w);
- }
- assert.equal(null, w.next);
- // completely flushed
- assert.ok(!w.firstBucket);
- assert.ok(!w.lastBucket);
-
- ncomplete++;
- if (cb) cb();
- });
-
-
- // Insert watcher into dumpQueue
- w.next = IOWatcher.dumpQueue.next;
- IOWatcher.dumpQueue.next = w;
-
- w.firstBucket = { data: b };
- w.lastBucket = w.firstBucket;
- w.queueSize = b.length;
-
- for (var i = 0; i < N-1; i++) {
- var bucket = { data: b };
- assert.ok(!w.lastBucket.next);
- w.lastBucket.next = bucket;
- w.lastBucket = bucket;
- w.queueSize += b.length;
- }
-}
-
-
-function runTests (values) {
- expectedToComplete = values.length;
-
- function go () {
- if (ncomplete < values.length) {
- var v = values[ncomplete];
- console.log("test N=%d, size=%d", v[0], v[1].length);
- test(v[0], v[1], go);
- }
- }
-
- go();
-}
-
-runTests([ [3, Buffer(1000)],
- [30, Buffer(1000)],
- [4, Buffer(10000)],
- [1, "hello world\n"],
- [50, Buffer(1024*1024)],
- [500, Buffer(40960+1)],
- [500, Buffer(40960-1)],
- [500, Buffer(40960)],
- [500, Buffer(1024*1024+1)],
- [50000, "hello world\n"]
- ]);
-
-
-process.on('exit', function () {
- assert.equal(expectedToComplete, ncomplete);
-});
-
diff --git a/test/simple/test-pipe.js b/test/simple/test-pipe.js
index d12c2b163e8..75db48eabbb 100644
--- a/test/simple/test-pipe.js
+++ b/test/simple/test-pipe.js
@@ -17,22 +17,20 @@ var bufferSize = 5 * 1024 * 1024;
*/
var buffer = Buffer(bufferSize);
for (var i = 0; i < buffer.length; i++) {
- buffer[i] = 100; //parseInt(Math.random()*10000) % 256;
+ buffer[i] = parseInt(Math.random()*10000) % 256;
}
var web = http.Server(function (req, res) {
web.close();
- console.log("web server connection fd=%d", req.connection.fd);
-
console.log(req.headers);
var socket = net.Stream();
socket.connect(tcpPort);
socket.on('connect', function () {
- console.log('http->tcp connected fd=%d', socket.fd);
+ console.log('socket connected');
});
req.pipe(socket);
@@ -56,7 +54,7 @@ web.listen(webPort, startClient);
var tcp = net.Server(function (s) {
tcp.close();
- console.log("tcp server connection fd=%d", s.fd);
+ console.log("tcp server connection");
var i = 0;
@@ -93,11 +91,6 @@ function startClient () {
req.write(buffer);
req.end();
- console.log("request fd=%d", req.connection.fd);
-
- // note the queue includes http headers.
- assert.ok(req.connection.writeQueueSize() > buffer.length);
-
req.on('response', function (res) {
console.log('Got response');
res.setEncoding('utf8');
diff --git a/test/simple/test-sendfd.js b/test/simple/test-sendfd.js
index 8052a136673..7ed7b02c1a9 100644
--- a/test/simple/test-sendfd.js
+++ b/test/simple/test-sendfd.js
@@ -53,7 +53,7 @@ var logChild = function(d) {
d.split('\n').forEach(function(l) {
if (l.length > 0) {
- console.error('CHILD: ' + l);
+ common.debug('CHILD: ' + l);
}
});
};
@@ -96,18 +96,19 @@ var srv = net.createServer(function(s) {
buf.write(JSON.stringify(DATA) + '\n', 'utf8');
s.write(str, 'utf8', pipeFDs[1]);
-
- s.write(buf, pipeFDs[1], function () {
- console.error("close pipeFDs[1]");
+ if (s.write(buf, undefined, pipeFDs[1])) {
netBinding.close(pipeFDs[1]);
- });
+ } else {
+ s.addListener('drain', function() {
+ netBinding.close(pipeFDs[1]);
+ });
+ }
});
srv.listen(SOCK_PATH);
// Spawn a child running test/fixtures/recvfd.js
-var cp = child_process.spawn(process.execPath,
- [path.join(common.fixturesDir, 'recvfd.js'),
- SOCK_PATH]);
+var cp = child_process.spawn(process.argv[0],
+ [path.join(common.fixturesDir, 'recvfd.js'), SOCK_PATH]);
cp.stdout.addListener('data', logChild);
cp.stderr.addListener('data', logChild);