Browse files

Use simpler test case

  • Loading branch information...
1 parent e8ecfa8 commit fe82627d504b6c4c7e155e3a2b65d1eebebb37c4 @abram abram committed Apr 11, 2011
Showing with 24 additions and 60 deletions.
  1. +0 −60 test/simple/test-http-client-pipe.js
  2. +24 −0 test/simple/test-http-response-readable.js
View
60 test/simple/test-http-client-pipe.js
@@ -1,60 +0,0 @@
-var common = require('../common');
-var assert = require('assert');
-var http = require('http');
-var stream = require('stream');
-var util = require('util');
-
-function SlowStream() {
- stream.Stream.call(this);
- this.writable = true;
- this.output = '';
-}
-util.inherits(SlowStream, stream.Stream);
-
-SlowStream.prototype.write = function(buffer) {
- this.output += buffer.toString();
- console.log('wrote data.');
- var self = this;
- setTimeout(function() {
- self.emit('drain');
- }, 100);
- return false;
-};
-
-SlowStream.prototype.end = function() {
- testServer.close();
-};
-
-var chunks = ['hello ', 'world'];
-
-var testServer = new http.Server(function(req, res) {
- res.writeHead(200);
- res.write(chunks[0]);
- process.nextTick(function() {
- res.write(chunks[1]);
- process.nextTick(function() {
- res.end();
- });
- });
-});
-
-testServer.listen(common.PORT);
-
-var outputStream = new SlowStream();
-
-var request = http.get({
- host: 'localhost',
- port: common.PORT,
- path: '/',
-}, function(response) {
- response.on('data', function() { console.log('got some data'); });
- // If response.readable isn't being properly set to false, this will
- // cause an error, because the final time .resume() is called on the
- // response the underlying socket will already be closed.
- response.pipe(outputStream);
-});
-request.end();
-
-process.addListener('exit', function() {
- assert.equal(outputStream.output, chunks.join(''));
-});
View
24 test/simple/test-http-response-readable.js
@@ -0,0 +1,24 @@
+var common = require('../common');
+var assert = require('assert');
+var http = require('http');
+
+var testServer = new http.Server(function(req, res) {
+ res.writeHead(200);
+ res.write('Hello world');
+ res.end();
+});
+
+testServer.listen(common.PORT);
+
+var request = http.get({
+ host: 'localhost',
+ port: common.PORT,
+ path: '/',
+}, function(response) {
+ assert.equal(response.readable, true, 'response.readable initially true');
+ response.on('end', function() {
+ assert.equal(response.readable, false,
+ 'response.readable set to false after end');
+ testServer.close();
+ });
+});

0 comments on commit fe82627

Please sign in to comment.