diff options
| author | Ryan Dahl <ry@tinyclouds.org> | 2010-10-10 20:18:47 -0700 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2010-10-10 20:18:47 -0700 |
| commit | 393f0071e4cabc05d083a43e8da76f166b9d0f0a (patch) | |
| tree | f580c520a2af5f6a5dfe65a2aba9cae388a5a106 /test/disabled | |
| parent | 8ab691726d76026c123b4ad96bb771be94c96729 (diff) | |
| download | node-393f0071e4cabc05d083a43e8da76f166b9d0f0a.tar.gz | |
Improve pipe-test. Still not working
Diffstat (limited to 'test/disabled')
| -rw-r--r-- | test/disabled/pipe-test.js | 84 |
1 files changed, 77 insertions, 7 deletions
diff --git a/test/disabled/pipe-test.js b/test/disabled/pipe-test.js index 63ef73122..2b7e8cb46 100644 --- a/test/disabled/pipe-test.js +++ b/test/disabled/pipe-test.js @@ -1,14 +1,31 @@ -/* - * try with - * curl -d @/usr/share/dict/words http://localhost:8000/123 +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); +var net = require('net'); + +var listenCount = 0; +var gotThanks = false; +var tcpLengthSeen; + + +/* + * 5MB of random buffer. */ +var buffer = Buffer(1024 * 1024 * 5); +for (var i = 0; i < buffer.length; i++) { + buffer[i] = parseInt(Math.random()*10000); +} -http = require('http'); -s = http.Server(function (req, res) { +var web = http.Server(function (req, res) { + web.close(); + console.log(req.headers); - req.pipe(process.stdout, { end: false }); + var socket = net.Stream(); + socket.connect(tcpPort); + + req.pipe(socket); req.on('end', function () { res.writeHead(200); @@ -16,5 +33,58 @@ s = http.Server(function (req, res) { res.end(); }); }); +var webPort = common.PORT +web.listen(webPort, startClient); + + + +var tcp = net.Server(function (socket) { + tcp.close(); + + var i = 0; + + socket.on('data', function (d) { + for (var j = 0; j < d.length; j++) { + assert.equal(i % 256, d[i]); + i++; + } + }); + + socket.on('end', function () { + tcpLengthSeen = i; + socket.end(); + }); +}); +var tcpPort = webPort + 1; +tcp.listen(tcpPort, startClient); + + +function startClient () { + listenCount++; + console.log("listenCount %d" , listenCount); + if (listenCount < 2) { + console.log("dont start client %d" , listenCount); + return; + } + + console.log("start client"); + + var client = http.createClient(common.PORT); + var req = client.request('GET', '/'); + req.write(buffer); + req.end(); + + req.on('response', function (res) { + res.setEncoding('utf8'); + res.on('data', function (s) { + assert.equal("thanks", s); + gotThanks = true; + }); + }); +} + +process.on('exit', function () { + assert.ok(gotThanks); + assert.equal(1024*1024*5, tcpLengthSeen); +}); -s.listen(8000); |
