Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test-http-destroyed-socket-write2 #4970

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 12 additions & 46 deletions test/parallel/test-http-destroyed-socket-write2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
req.write('hello', function() {
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':
Expand All @@ -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();
});