|
1 | 1 | 'use strict';
|
2 |
| -var common = require('../common'); |
3 |
| -var assert = require('assert'); |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
4 | 4 |
|
5 | 5 | // Make sure that throwing in 'end' handler doesn't lock
|
6 | 6 | // up the socket forever.
|
7 | 7 | //
|
8 | 8 | // This is NOT a good way to handle errors in general, but all
|
9 | 9 | // the same, we should not be so brittle and easily broken.
|
10 | 10 |
|
11 |
| -var http = require('http'); |
| 11 | +const http = require('http'); |
12 | 12 |
|
13 |
| -var n = 0; |
14 |
| -var server = http.createServer(function(req, res) { |
| 13 | +let n = 0; |
| 14 | +const server = http.createServer((req, res) => { |
15 | 15 | if (++n === 10) server.close();
|
16 | 16 | res.end('ok');
|
17 | 17 | });
|
18 | 18 |
|
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) => { |
24 | 23 | res.resume();
|
25 |
| - res.on('end', function() { |
| 24 | + res.on('end', common.mustCall(() => { |
26 | 25 | throw new Error('gleep glorp');
|
27 |
| - }); |
| 26 | + })); |
28 | 27 | });
|
29 | 28 | req.end();
|
30 | 29 | }
|
31 |
| -}); |
| 30 | +})); |
32 | 31 |
|
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', () => { |
41 | 34 | errors++;
|
42 |
| -} |
| 35 | +}); |
43 | 36 |
|
44 |
| -process.on('exit', function() { |
| 37 | +process.on('exit', () => { |
45 | 38 | assert.equal(errors, 10);
|
46 |
| - console.log('ok'); |
47 | 39 | });
|
0 commit comments