test: refactor test-http-destroyed-socket-write2
Remove the limit of requests to be sent (128) as in some conditions it was reached without the `error` event being fired, causing the test to fail. Remove the initial timeout. Remove some variables used to check the validity of the test and replace them with `common.mustCall` and `common.fail` calls. PR-URL: https://github.com/nodejs/node/pull/4970 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Klauke <romaaan.git@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
c4b5a451e3
commit
b920d4546f
@ -19,28 +19,13 @@ server.listen(common.PORT, function() {
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
var timer = setTimeout(write, 50);
|
||||
var writes = 0;
|
||||
|
||||
function write() {
|
||||
if (++writes === 128) {
|
||||
clearTimeout(timer);
|
||||
req.end();
|
||||
test();
|
||||
} else {
|
||||
req.write('hello', function() {
|
||||
timer = setImmediate(write);
|
||||
setImmediate(write);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var gotError = false;
|
||||
var sawData = false;
|
||||
var sawEnd = false;
|
||||
|
||||
req.on('error', function(er) {
|
||||
assert(!gotError);
|
||||
gotError = true;
|
||||
req.on('error', common.mustCall(function(er) {
|
||||
switch (er.code) {
|
||||
// This is the expected case
|
||||
case 'ECONNRESET':
|
||||
@ -56,39 +41,20 @@ server.listen(common.PORT, function() {
|
||||
'Writing to a torn down client should RESET or ABORT');
|
||||
break;
|
||||
}
|
||||
clearTimeout(timer);
|
||||
console.log('ECONNRESET was raised after %d writes', writes);
|
||||
test();
|
||||
});
|
||||
|
||||
assert.equal(req.output.length, 0);
|
||||
assert.equal(req.outputEncodings.length, 0);
|
||||
server.close();
|
||||
}));
|
||||
|
||||
req.on('response', function(res) {
|
||||
res.on('data', function(chunk) {
|
||||
console.error('saw data: ' + chunk);
|
||||
sawData = true;
|
||||
common.fail('Should not receive response data');
|
||||
});
|
||||
res.on('end', function() {
|
||||
console.error('saw end');
|
||||
sawEnd = true;
|
||||
common.fail('Should not receive response end');
|
||||
});
|
||||
});
|
||||
|
||||
var closed = false;
|
||||
|
||||
function test() {
|
||||
if (closed)
|
||||
return;
|
||||
|
||||
server.close();
|
||||
closed = true;
|
||||
|
||||
if (req.output.length || req.outputEncodings.length)
|
||||
console.error('bad happened', req.output, req.outputEncodings);
|
||||
|
||||
assert.equal(req.output.length, 0);
|
||||
assert.equal(req.outputEncodings, 0);
|
||||
assert(gotError);
|
||||
assert(!sawData);
|
||||
assert(!sawEnd);
|
||||
console.log('ok');
|
||||
}
|
||||
write();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user