Skip to content

Commit

Permalink
fix http keep-alive test case
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse committed Dec 2, 2015
1 parent 920f9db commit 42382b4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"vary": "^1.0.0"
},
"devDependencies": {
"agentkeepalive": "~2.0.3",
"babel": "^5.0.0",
"freeport": "~1.0.5",
"istanbul": "^0.4.0",
"make-lint": "^1.0.1",
"mocha": "^2.0.1",
Expand Down
62 changes: 41 additions & 21 deletions test/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
'use strict';

var stderr = require('test-console').stderr;
var Agent = require('agentkeepalive');
var request = require('supertest');
var statuses = require('statuses');
var freeport = require('freeport');
var pedding = require('pedding');
var assert = require('assert');
var urllib = require('urllib');
Expand Down Expand Up @@ -896,29 +898,47 @@ describe('app.respond', function(){
})
})

it('should not destroy keepalive connection', function(done){
done = pedding(2, done);
var app = koa();
app.use(function *(){
var remote = yield urllib.request('http://koajs.com', {
streaming: true,
headers: {
connection: 'keep-alive'
}
describe('when .body is a http keepalive IncommingMessage', () => {
var target;
var port;
before(function(done){
var app = koa();
app.use(function *(){
this.body = fs.createReadStream(__filename);
});
var res = remote.res;
this.body = res;
res.once('end', function(){
assert.equal(res.readable, false);
assert.equal(res.socket.destroyed, false);
done();
}.bind(this));
});

var server = app.listen();
request(server)
.head('/')
.expect(200, done);
freeport(function(err, p){
port = p || 12384;
target = app.listen(port, done);
});
})

after(function(){
target.close();
})

it('should not destroy keepalive connection', function(done){
done = pedding(2, done);
var app = koa();
app.use(function *(){
var remote = yield urllib.request('http://127.0.0.1:' + port, {
streaming: true,
agent: new Agent()
});
var res = remote.res;
this.body = res;
res.once('end', function(){
assert.equal(res.readable, false);
assert.equal(res.socket.destroyed, false);
done();
});
});

var server = app.listen();
request(server)
.head('/')
.expect(200, done);
})
})

describe('when .body is an Object', function(){
Expand Down

0 comments on commit 42382b4

Please sign in to comment.