node/test/addons/make-callback-recurse/test.js
Daniel Bevenius fdca79fbc0 test: enable addons test to pass with debug build
Currently when running configure with the --debug option in combination
with the tests (./configure --debug && make -j8 test) there are a few
addon tests that fail with error messages similar to this:

=== release test ===
Path: addons/load-long-path/test
fs.js:558
  return binding.open(pathModule._makeLong(path), stringToFlags(flags),
mode);
                 ^

Error: ENOENT: no such file or directory, open
'/nodejs/node/test/addons/load-long-path/build/Release/binding.node'
    at Object.fs.openSync (fs.js:558:18)
    at Object.fs.readFileSync (fs.js:468:33)
    at Object.<anonymous>
(/nodejs/node/test/addons/load-long-path/test.js:28:19)
    at Module._compile (module.js:560:32)
    at Object.Module._extensions..js (module.js:569:10)
    at Module.load (module.js:477:32)
    at tryModuleLoad (module.js:436:12)
    at Function.Module._load (module.js:428:3)
    at Module.runMain (module.js:594:10)
    at run (bootstrap_node.js:382:7)
Command: out/Release/node
/nodejs/node/test/addons/load-long-path/test.js

This commit allows for the tests to pass even if the configured build
type is of type debug.

PR-URL: https://github.com/nodejs/node/pull/8836
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-10-06 10:27:30 -07:00

170 lines
5.5 KiB
JavaScript

'use strict';
const common = require('../../common');
const assert = require('assert');
const domain = require('domain');
const binding = require(`./build/${common.buildType}/binding`);
const makeCallback = binding.makeCallback;
// Make sure this is run in the future.
const mustCallCheckDomains = common.mustCall(checkDomains);
// Make sure that using MakeCallback allows the error to propagate.
assert.throws(function() {
makeCallback({}, function() {
throw new Error('hi from domain error');
});
});
// Check the execution order of the nextTickQueue and MicrotaskQueue in
// relation to running multiple MakeCallback's from bootstrap,
// node::MakeCallback() and node::AsyncWrap::MakeCallback().
// TODO(trevnorris): Is there a way to verify this is being run during
// bootstrap?
(function verifyExecutionOrder(arg) {
const results = [];
// Processing of the MicrotaskQueue is manually handled by node. They are not
// processed until after the nextTickQueue has been processed.
Promise.resolve(1).then(common.mustCall(function() {
results.push(7);
}));
// The nextTick should run after all immediately invoked calls.
process.nextTick(common.mustCall(function() {
results.push(3);
// Run same test again but while processing the nextTickQueue to make sure
// the following MakeCallback call breaks in the middle of processing the
// queue and allows the script to run normally.
process.nextTick(common.mustCall(function() {
results.push(6);
}));
makeCallback({}, common.mustCall(function() {
results.push(4);
}));
results.push(5);
}));
results.push(0);
// MakeCallback is calling the function immediately, but should then detect
// that a script is already in the middle of execution and return before
// either the nextTickQueue or MicrotaskQueue are processed.
makeCallback({}, common.mustCall(function() {
results.push(1);
}));
// This should run before either the nextTickQueue or MicrotaskQueue are
// processed. Previously MakeCallback would not detect this circumstance
// and process them immediately.
results.push(2);
setImmediate(common.mustCall(function() {
for (var i = 0; i < results.length; i++) {
assert.strictEqual(results[i], i,
`verifyExecutionOrder(${arg}) results: ${results}`);
}
if (arg === 1) {
// The tests are first run on bootstrap during LoadEnvironment() in
// src/node.cc. Now run the tests through node::MakeCallback().
setImmediate(function() {
makeCallback({}, common.mustCall(function() {
verifyExecutionOrder(2);
}));
});
} else if (arg === 2) {
// setTimeout runs via the TimerWrap, which runs through
// AsyncWrap::MakeCallback(). Make sure there are no conflicts using
// node::MakeCallback() within it.
setTimeout(common.mustCall(function() {
verifyExecutionOrder(3);
}), 10);
} else if (arg === 3) {
mustCallCheckDomains();
} else {
throw new Error('UNREACHABLE');
}
}));
}(1));
function checkDomains() {
// Check that domains are properly entered/exited when called in multiple
// levels from both node::MakeCallback() and AsyncWrap::MakeCallback
setImmediate(common.mustCall(function() {
const d1 = domain.create();
const d2 = domain.create();
const d3 = domain.create();
makeCallback({domain: d1}, common.mustCall(function() {
assert.strictEqual(d1, process.domain);
makeCallback({domain: d2}, common.mustCall(function() {
assert.strictEqual(d2, process.domain);
makeCallback({domain: d3}, common.mustCall(function() {
assert.strictEqual(d3, process.domain);
}));
assert.strictEqual(d2, process.domain);
}));
assert.strictEqual(d1, process.domain);
}));
}));
setTimeout(common.mustCall(function() {
const d1 = domain.create();
const d2 = domain.create();
const d3 = domain.create();
makeCallback({domain: d1}, common.mustCall(function() {
assert.strictEqual(d1, process.domain);
makeCallback({domain: d2}, common.mustCall(function() {
assert.strictEqual(d2, process.domain);
makeCallback({domain: d3}, common.mustCall(function() {
assert.strictEqual(d3, process.domain);
}));
assert.strictEqual(d2, process.domain);
}));
assert.strictEqual(d1, process.domain);
}));
}), 1);
// Make sure nextTick, setImmediate and setTimeout can all recover properly
// after a thrown makeCallback call.
process.nextTick(common.mustCall(function() {
const d = domain.create();
d.on('error', common.mustCall(function(e) {
assert.strictEqual(e.message, 'throw from domain 3');
}));
makeCallback({domain: d}, function() {
throw new Error('throw from domain 3');
});
throw new Error('UNREACHABLE');
}));
setImmediate(common.mustCall(function() {
const d = domain.create();
d.on('error', common.mustCall(function(e) {
assert.strictEqual(e.message, 'throw from domain 2');
}));
makeCallback({domain: d}, function() {
throw new Error('throw from domain 2');
});
throw new Error('UNREACHABLE');
}));
setTimeout(common.mustCall(function() {
const d = domain.create();
d.on('error', common.mustCall(function(e) {
assert.strictEqual(e.message, 'throw from domain 1');
}));
makeCallback({domain: d}, function() {
throw new Error('throw from domain 1');
});
throw new Error('UNREACHABLE');
}));
}