[fix test] handle proxy error since we are properly aborting the proxy Request

This commit is contained in:
Jarrett Cruger 2014-04-14 13:17:18 -04:00
parent 77a1cff9bc
commit 61c8734e8b

View File

@ -78,14 +78,14 @@ describe('lib/http-proxy.js', function() {
}); });
source.listen(ports.source); source.listen(ports.source);
http.request({ http.request({
hostname: '127.0.0.1', hostname: '127.0.0.1',
port: ports.proxy, port: ports.proxy,
method: 'POST', method: 'POST',
headers: { headers: {
'x-forwarded-for': '127.0.0.1' 'x-forwarded-for': '127.0.0.1'
} }
}, function() {}).end(); }, function() {}).end();
}); });
}); });
@ -105,7 +105,7 @@ describe('lib/http-proxy.js', function() {
}); });
source.listen(ports.source); source.listen(ports.source);
http.request({ http.request({
hostname: '127.0.0.1', hostname: '127.0.0.1',
port: ports.proxy, port: ports.proxy,
@ -117,7 +117,7 @@ describe('lib/http-proxy.js', function() {
expect(data.toString()).to.eql('Hello from ' + ports.source); expect(data.toString()).to.eql('Hello from ' + ports.source);
}); });
res.on('end', function () { res.on('end', function () {
source.close(); source.close();
proxy._server.close(); proxy._server.close();
done(); done();
@ -141,7 +141,7 @@ describe('lib/http-proxy.js', function() {
}) })
proxy.listen(ports.proxy); proxy.listen(ports.proxy);
http.request({ http.request({
hostname: '127.0.0.1', hostname: '127.0.0.1',
port: ports.proxy, port: ports.proxy,
@ -159,6 +159,11 @@ describe('lib/http-proxy.js', function() {
timeout: 3 timeout: 3
}).listen(ports.proxy); }).listen(ports.proxy);
proxy.on('error', function (e) {
expect(e).to.be.an(Error);
expect(e.code).to.be.eql('ECONNRESET');
});
var source = http.createServer(function(req, res) { var source = http.createServer(function(req, res) {
setTimeout(function () { setTimeout(function () {
res.end('At this point the socket should be closed'); res.end('At this point the socket should be closed');
@ -207,7 +212,7 @@ describe('lib/http-proxy.js', function() {
// proxy.ee.on('http-proxy:**', function (uno, dos, tres) { // proxy.ee.on('http-proxy:**', function (uno, dos, tres) {
// events.push(this.event); // events.push(this.event);
// }) // })
// http.request({ // http.request({
// hostname: '127.0.0.1', // hostname: '127.0.0.1',
// port: '8081', // port: '8081',
@ -314,4 +319,4 @@ describe('lib/http-proxy.js', function() {
}) })
}); });
}) })
}); });