From 393f0071e4cabc05d083a43e8da76f166b9d0f0a Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 10 Oct 2010 20:18:47 -0700 Subject: [PATCH] Improve pipe-test. Still not working --- test/disabled/pipe-test.js | 84 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/test/disabled/pipe-test.js b/test/disabled/pipe-test.js index 63ef731..2b7e8cb 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); -- 2.7.4