diff --git a/lib/circuit.js b/lib/circuit.js index ad39e306..8b590eba 100644 --- a/lib/circuit.js +++ b/lib/circuit.js @@ -638,7 +638,7 @@ function fail (circuit, err, args, latency) { * @event CircuitBreaker#failure * @type {Error} */ - circuit.emit('failure', err, latency); + circuit.emit('failure', err, latency, args); if (circuit.warmUp) return; // check stats to see if the circuit should be opened diff --git a/test/test.js b/test/test.js index 42305c9a..484a60a1 100644 --- a/test/test.js +++ b/test/test.js @@ -795,6 +795,23 @@ test('Circuit Breaker failure event emits latency', t => { breaker.fire(-1).catch(noop); }); +test('Circuit Breaker failure event emits function parameters', t => { + t.plan(6); + const breaker = circuit(passFail); + breaker.on('failure', (result, latencyTime, args) => { + t.ok(args, 'third argument is the latency'); + t.equal(Array.isArray(args), true, 'The args parameter is an array'); + t.equal(args[0], -1, 'this is the first argument'); + t.equal(args[1].arg1, 'arg1', 'this is the second argument object'); + t.equal(args[1].arg2, 'arg2', 'this is the second argument object'); + t.equal(args[2][0], '1', 'this is the third argument'); + breaker.shutdown(); + t.end(); + }); + + breaker.fire(-1, { arg1: 'arg1', arg2: 'arg2' }, ['1', '2']).catch(noop); +}); + test('Circuit Breaker timeout event emits latency', t => { t.plan(1); const breaker = circuit(slowFunction, { timeout: 10 });