hooks: Rewrite callAll and aCallAll for consistency

Rewrite the `callAll` and `aCallAll` functions to support all
reasonable hook behaviors and to report errors for unreasonable
behaviors (e.g., calling the callback twice).

Now a hook function like the following works as expected when invoked
by `aCallAll`:

```
exports.myHookFn = (hookName, context, cb) => {
  cb('some value');
  return;
};
```
This commit is contained in:
Richard Hansen 2020-10-08 01:42:49 -04:00 committed by John McLear
parent 79119baf58
commit 36aceb3aba
6 changed files with 1400 additions and 74 deletions

View file

@ -1,7 +1,10 @@
/* global __dirname, exports, require */
function m(mod) { return __dirname + '/../../src/' + mod; }
const apiHandler = require(m('node/handler/APIHandler'));
const log4js = require(m('node_modules/log4js'));
const process = require('process');
const server = require(m('node/server'));
const settings = require(m('node/utils/Settings'));
const supertest = require(m('node_modules/supertest'));
@ -18,6 +21,10 @@ exports.logger = log4js.getLogger('test');
const logLevel = exports.logger.level;
// Mocha doesn't monitor unhandled Promise rejections, so convert them to uncaught exceptions.
// https://github.com/mochajs/mocha/issues/2640
process.on('unhandledRejection', (reason, promise) => { throw reason; });
exports.init = async function() {
if (inited) return exports.agent;
inited = true;