diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2011-02-17 21:04:51 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-02-17 21:06:16 -0800 |
commit | 15a6aa75009e285113e4cc2b13daaf5c67633fb7 (patch) | |
tree | 7d42d8da4a8acdfaa1cb59d86242914de8892422 | |
parent | 7e4f7550738d0a232978629535d6db34e380b04e (diff) | |
download | nodejs-15a6aa75009e285113e4cc2b13daaf5c67633fb7.tar.gz nodejs-15a6aa75009e285113e4cc2b13daaf5c67633fb7.tar.bz2 nodejs-15a6aa75009e285113e4cc2b13daaf5c67633fb7.zip |
Add more broken tests
-rw-r--r-- | test/simple/test-http-agent2.js | 63 | ||||
-rw-r--r-- | test/simple/test-http-eof-before-eom.js | 72 |
2 files changed, 135 insertions, 0 deletions
diff --git a/test/simple/test-http-agent2.js b/test/simple/test-http-agent2.js new file mode 100644 index 000000000..eed1cb90d --- /dev/null +++ b/test/simple/test-http-agent2.js @@ -0,0 +1,63 @@ +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); + +var reqEndCount = 0; + +var server = http.Server(function(req, res) { + res.writeHead(200); + res.end("hello world\n"); + + var buffer = ''; + + req.setEncoding('utf8'); + + req.on('data', function(s) { + buffer += s; + }); + + req.on('end', function() { + reqEndCount++; + assert.equal(body, buffer); + }); +}); + +var responses = 0; +var N = 10; +var M = 10; + +var body = '' +for (var i = 0; i < 1000; i++) { + body += 'hello world'; +} + +var options = { + port: common.PORT, + path: '/', + method: 'PUT' +}; + +server.listen(common.PORT, function() { + for (var i = 0; i < N; i++) { + setTimeout(function () { + for (var j = 0; j < M; j++) { + + var req = http.request(options, function(res) { + console.log(res.statusCode); + if (++responses == N * M) server.close(); + }).on('error', function(e) { + console.log(e.message); + process.exit(1); + }); + + req.end(body); + } + }, i); + } +}); + + +process.on('exit', function() { + assert.equal(N * M, responses); + assert.equal(N * M, reqEndCount); +}); diff --git a/test/simple/test-http-eof-before-eom.js b/test/simple/test-http-eof-before-eom.js new file mode 100644 index 000000000..d67881f5a --- /dev/null +++ b/test/simple/test-http-eof-before-eom.js @@ -0,0 +1,72 @@ +// I hate HTTP. One way of terminating an HTTP response is to not send +// a content-length header, not send a transfer-encoding: chunked header, +// and simply terminate the TCP connection. That is identity +// transfer-encoding. +// +// This test is to be sure that the https client is handling this case +// correctly. +if (!process.versions.openssl) { + console.error('Skipping because node compiled without OpenSSL.'); + process.exit(0); +} + +var common = require('../common'); +var assert = require('assert'); +var net = require('net'); +var http = require('http'); +var fs = require('fs'); + + +var server = net.Server(function(socket) { + console.log('2) Server got request'); + socket.write('HTTP/1.1 200 OK\r\n' + + 'Content-Length: 200\r\n'); + + // note headers are incomplete. + + setTimeout(function() { + socket.end('Server: gws\r\n'); + console.log('4) Server finished response'); + }, 100); +}); + + +var gotHeaders = false; +var gotEnd = false; +var bodyBuffer = ''; + +server.listen(common.PORT, function() { + console.log('1) Making Request'); + var req = http.get({ port: common.PORT }, function(res) { + server.close(); + console.log('3) Client got response headers.'); + + assert.equal('gws', res.headers.server); + gotHeaders = true; + + res.setEncoding('utf8'); + res.on('data', function(s) { + bodyBuffer += s; + }); + + res.on('aborted', function() { + console.log('RESPONSE ABORTED'); + }); + + req.connection.on('error', function() { + console.log('INCOMOLETE'); + }); + + res.on('end', function() { + console.log('5) Client got "end" event.'); + gotEnd = true; + }); + }); +}); + +process.on('exit', function() { + assert.ok(gotHeaders); + assert.ok(gotEnd); + assert.equal('hello\nworld\n', bodyBuffer); +}); + |