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 b496374

Browse filesBrowse files
edsadrItalo A. Casas
authored andcommitted
test: improve code in test-domain-multi
* use common.mustCall to validate functions executions * use common.fail to control error * remove unnecessary variables * remove unnecessary assertions * remove console.log and console.error * use arrow functions PR-URL: #10798 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 46bbabe commit b496374
Copy full SHA for b496374

File tree

Expand file treeCollapse file tree

1 file changed

+11
-34
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-34
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-domain-multi.js‎

Copy file name to clipboard
+11-34Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
'use strict';
22
// Tests of multiple domains happening at once.
33

4-
require('../common');
5-
const assert = require('assert');
4+
const common = require('../common');
65
const domain = require('domain');
7-
8-
let caughtA = false;
9-
let caughtB = false;
10-
let caughtC = false;
11-
6+
const http = require('http');
127

138
const a = domain.create();
149
a.enter(); // this will be our "root" domain
15-
a.on('error', function(er) {
16-
caughtA = true;
17-
console.log('This should not happen');
18-
throw er;
19-
});
2010

11+
a.on('error', common.fail);
2112

22-
const http = require('http');
23-
const server = http.createServer(function(req, res) {
13+
const server = http.createServer((req, res) => {
2414
// child domain of a.
2515
const b = domain.create();
2616
a.add(b);
@@ -31,47 +21,34 @@ const server = http.createServer(function(req, res) {
3121
b.add(req);
3222
b.add(res);
3323

34-
b.on('error', function(er) {
35-
caughtB = true;
36-
console.error('Error encountered', er);
24+
b.on('error', common.mustCall((er) => {
3725
if (res) {
3826
res.writeHead(500);
3927
res.end('An error occurred');
4028
}
4129
// res.writeHead(500), res.destroy, etc.
4230
server.close();
43-
});
31+
}));
4432

4533
// XXX this bind should not be necessary.
4634
// the write cb behavior in http/net should use an
4735
// event so that it picks up the domain handling.
48-
res.write('HELLO\n', b.bind(function() {
36+
res.write('HELLO\n', b.bind(() => {
4937
throw new Error('this kills domain B, not A');
5038
}));
5139

52-
}).listen(0, function() {
40+
}).listen(0, () => {
5341
const c = domain.create();
54-
const req = http.get({ host: 'localhost', port: this.address().port });
42+
const req = http.get({ host: 'localhost', port: server.address().port });
5543

5644
// add the request to the C domain
5745
c.add(req);
5846

59-
req.on('response', function(res) {
60-
console.error('got response');
47+
req.on('response', (res) => {
6148
// add the response object to the C domain
6249
c.add(res);
6350
res.pipe(process.stdout);
6451
});
6552

66-
c.on('error', function(er) {
67-
caughtC = true;
68-
console.error('Error on c', er.message);
69-
});
70-
});
71-
72-
process.on('exit', function() {
73-
assert.strictEqual(caughtA, false);
74-
assert.strictEqual(caughtB, true);
75-
assert.strictEqual(caughtC, true);
76-
console.log('ok - Errors went where they were supposed to go');
53+
c.on('error', common.mustCall((er) => { }));
7754
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.