Skip to content

Commit

Permalink
test: port domains regression test from v0.10
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dohse authored and Julien Gilli committed Oct 16, 2015
1 parent b52142f commit 642928b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/parallel/test-domain-top-level-error-handler-clears-stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const common = require('../common');
const domain = require('domain');

/*
* Make sure that the domains stack is cleared after a top-level domain
* error handler exited gracefully.
*/
const d = domain.create();

d.on('error', common.mustCall(function() {
process.nextTick(function() {
// Scheduling a callback with process.nextTick will enter a _new_ domain,
// and the callback will be called after the domain that handled the error
// was exited. So there should be only one domain on the domains stack if
// the domains stack was cleared properly when the domain error handler
// returned.
if (domain._stack.length !== 1) {
// Do not use assert to perform this test: this callback runs in a
// different callstack as the original process._fatalException that
// handled the original error, thus throwing here would trigger another
// call to process._fatalException, and so on recursively and
// indefinitely.
console.error('domains stack length should be 1, but instead is:',
domain._stack.length);
process.exit(1);
}
});
}));

d.run(function() {
throw new Error('Error from domain');
});

0 comments on commit 642928b

Please sign in to comment.