Skip to content

Commit 3d4d577

Browse files
santigimenoMyles Borins
authored and
Myles Borins
committed
test: refactor http-end-throw-socket-handling
Remove timer to avoid the test timing out occasionally. PR-URL: #5676 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
1 parent 918d33a commit 3d4d577

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
3+
const assert = require('assert');
44

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

11-
var http = require('http');
11+
const http = require('http');
1212

13-
var n = 0;
14-
var server = http.createServer(function(req, res) {
13+
let n = 0;
14+
const server = http.createServer((req, res) => {
1515
if (++n === 10) server.close();
1616
res.end('ok');
1717
});
1818

19-
server.listen(common.PORT, function() {
20-
for (var i = 0; i < 10; i++) {
21-
var options = { port: common.PORT };
22-
23-
var req = http.request(options, function(res) {
19+
server.listen(common.PORT, common.mustCall(() => {
20+
for (let i = 0; i < 10; i++) {
21+
const options = { port: common.PORT };
22+
const req = http.request(options, (res) => {
2423
res.resume();
25-
res.on('end', function() {
24+
res.on('end', common.mustCall(() => {
2625
throw new Error('gleep glorp');
27-
});
26+
}));
2827
});
2928
req.end();
3029
}
31-
});
30+
}));
3231

33-
setTimeout(function() {
34-
process.removeListener('uncaughtException', catcher);
35-
throw new Error('Taking too long!');
36-
}, common.platformTimeout(1000)).unref();
37-
38-
process.on('uncaughtException', catcher);
39-
var errors = 0;
40-
function catcher() {
32+
let errors = 0;
33+
process.on('uncaughtException', () => {
4134
errors++;
42-
}
35+
});
4336

44-
process.on('exit', function() {
37+
process.on('exit', () => {
4538
assert.equal(errors, 10);
46-
console.log('ok');
4739
});

0 commit comments

Comments
 (0)