Browse Source

test: port domains regression test from v0.10

f2a45caf2e contained a test for a
regression that had been introduced by the original change that
77a10ed05f ported. While
77a10ed05f did not contain that
regression, the test that f2a45caf2e
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

  caeb67735b 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: https://github.com/joyent/node/pull/9364
  Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  Reviewed-By: Julien Gilli <julien.gilli@joyent.com>

PR: #3356
PR-URL: https://github.com/nodejs/node/pull/3356
Reviewed-By: Ben Noordhuis <ben@strongloop.com>
v5.x
Jonas Dohse 9 years ago
committed by Rod Vagg
parent
commit
e2b8393ee8
  1. 34
      test/parallel/test-domain-top-level-error-handler-clears-stack.js

34
test/parallel/test-domain-top-level-error-handler-clears-stack.js

@ -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');
});
Loading…
Cancel
Save