Skip to content

Commit e2b8393

Browse files
dohservagg
authored andcommitted
test: port domains regression test from v0.10
f2a45ca contained a test for a regression that had been introduced by the original change that 77a10ed ported. While 77a10ed did not contain that regression, the test that f2a45ca contained should still be in the code base to prevent any regression from happening in the future. Original message for the commit that contained the test: domains: fix stack clearing after error handled caeb677 introduced a regression where the domains stack would not be cleared after an error had been handled by the top-level domain. This change clears the domains stack regardless of the position of the active domain in the stack. PR: #9364 PR-URL: nodejs/node-v0.x-archive#9364 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Julien Gilli <[email protected]> PR: #3356 PR-URL: #3356 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 676e618 commit e2b8393

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const domain = require('domain');
5+
6+
/*
7+
* Make sure that the domains stack is cleared after a top-level domain
8+
* error handler exited gracefully.
9+
*/
10+
const d = domain.create();
11+
12+
d.on('error', common.mustCall(function() {
13+
process.nextTick(function() {
14+
// Scheduling a callback with process.nextTick will enter a _new_ domain,
15+
// and the callback will be called after the domain that handled the error
16+
// was exited. So there should be only one domain on the domains stack if
17+
// the domains stack was cleared properly when the domain error handler
18+
// returned.
19+
if (domain._stack.length !== 1) {
20+
// Do not use assert to perform this test: this callback runs in a
21+
// different callstack as the original process._fatalException that
22+
// handled the original error, thus throwing here would trigger another
23+
// call to process._fatalException, and so on recursively and
24+
// indefinitely.
25+
console.error('domains stack length should be 1, but instead is:',
26+
domain._stack.length);
27+
process.exit(1);
28+
}
29+
});
30+
}));
31+
32+
d.run(function() {
33+
throw new Error('Error from domain');
34+
});

0 commit comments

Comments
 (0)