test: add a test case for *respond !socket.writable

https://github.com/koajs/koa/commit/9fe483ca767b64de3e9b9e2c78b7bfaf4208
61c2#diff-5372f626ee15242f1e2c6eb31655b4faR187
This commit is contained in:
Jonathan Ong 2013-12-25 00:13:54 -08:00
parent d3e3c4d117
commit 23548b6c97

View file

@ -23,6 +23,28 @@ describe('app', function(){
.get('/') .get('/')
.end(function(){}); .end(function(){});
}) })
it('should not .writeHead when !socket.writable', function(done){
var app = koa();
app.use(function *(next){
// set .writable to false
this.socket.writable = false;
this.status = 204;
// throw if .writeHead or .end is called
this.res.writeHead =
this.res.end = function () {
throw new Error('response sent');
};
})
// hackish, but the response should occur in a single ticket
setImmediate(done);
request(app.listen())
.get('/')
.end(function(){});
})
}) })
describe('app.use(fn)', function(){ describe('app.use(fn)', function(){