Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d4d577

Browse filesBrowse files
santigimenoMyles Borins
authored andcommitted
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
Copy full SHA for 3d4d577

File tree

Expand file treeCollapse file tree

1 file changed

+16
-24
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-24
lines changed
Open diff view settings
Collapse file
+16-24Lines changed: 16 additions & 24 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.