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 http-end-throw-socket-handling #5676

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
40 changes: 16 additions & 24 deletions test/parallel/test-http-end-throw-socket-handling.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');

// Make sure that throwing in 'end' handler doesn't lock
// up the socket forever.
//
// This is NOT a good way to handle errors in general, but all
// the same, we should not be so brittle and easily broken.

var http = require('http');
const http = require('http');

var n = 0;
var server = http.createServer(function(req, res) {
let n = 0;
const server = http.createServer((req, res) => {
if (++n === 10) server.close();
res.end('ok');
});

server.listen(common.PORT, function() {
for (var i = 0; i < 10; i++) {
var options = { port: common.PORT };

var req = http.request(options, function(res) {
server.listen(common.PORT, common.mustCall(() => {
for (let i = 0; i < 10; i++) {
const options = { port: common.PORT };
const req = http.request(options, (res) => {
res.resume();
res.on('end', function() {
res.on('end', common.mustCall(() => {
throw new Error('gleep glorp');
});
}));
});
req.end();
}
});
}));

setTimeout(function() {
process.removeListener('uncaughtException', catcher);
throw new Error('Taking too long!');
}, common.platformTimeout(1000)).unref();

process.on('uncaughtException', catcher);
var errors = 0;
function catcher() {
let errors = 0;
process.on('uncaughtException', () => {
errors++;
}
});

process.on('exit', function() {
process.on('exit', () => {
assert.equal(errors, 10);
console.log('ok');
});