Fix test-http-conn-reset.js on OSX

This commit is contained in:
Ryan Dahl 2011-10-12 17:31:32 -07:00
parent 39987cbc80
commit 3a34972672
2 changed files with 11 additions and 5 deletions

View File

@ -1071,6 +1071,14 @@ ClientRequest.prototype.abort = function() {
} }
}; };
function createHangUpError() {
var error = new Error('socket hang up');
error.code = 'ECONNRESET';
return error;
}
ClientRequest.prototype.onSocket = function(socket) { ClientRequest.prototype.onSocket = function(socket) {
var req = this; var req = this;
process.nextTick(function () { process.nextTick(function () {
@ -1128,7 +1136,7 @@ ClientRequest.prototype.onSocket = function(socket) {
if (!req.res) { if (!req.res) {
// If we don't have a response then we know that the socket // If we don't have a response then we know that the socket
// ended prematurely and we need to emit an error on the request. // ended prematurely and we need to emit an error on the request.
req.emit('error', new Error("Request ended prematurely.")); req.emit('error', createHangUpError());
req._hadError = true; req._hadError = true;
} }
parser.finish(); parser.finish();
@ -1148,9 +1156,7 @@ ClientRequest.prototype.onSocket = function(socket) {
// This socket error fired before we started to // This socket error fired before we started to
// receive a response. The error needs to // receive a response. The error needs to
// fire on the request. // fire on the request.
var error = new Error('socket hang up'); req.emit('error', createHangUpError());
error.code = 'ECONNRESET';
req.emit('error', error);
} }
} }
socket.on('close', closeListener); socket.on('close', closeListener);

View File

@ -44,8 +44,8 @@ function onListen() {
assert.ok(false, 'this should never run'); assert.ok(false, 'this should never run');
}); });
req.on('error', function(err) { req.on('error', function(err) {
assert.equal(err.message, 'socket hang up');
assert.equal(err.code, 'ECONNRESET'); assert.equal(err.code, 'ECONNRESET');
assert.equal(err.message, 'socket hang up');
caughtError = true; caughtError = true;
}); });
req.end(); req.end();