Skip to content

Commit

Permalink
fix: remove default maxFailures option
Browse files Browse the repository at this point in the history
And clean up error output during tests.
  • Loading branch information
lance committed Apr 3, 2017
1 parent 245d47b commit be65d3b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const defaults = {
timeout: 10000, // 10 seconds
maxFailures: 10,
errorThresholdPercentage: 50,
resetTimeout: 30000, // 30 seconds
Promise: Fidelity
};
Expand Down
1 change: 0 additions & 1 deletion lib/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class CircuitBreaker extends EventEmitter {
this.options = options;
this.options.rollingCountTimeout = options.rollingCountTimeout || 10000;
this.options.rollingCountBuckets = options.rollingCountBuckets || 10;
this.options.errorThresholdPercentage = 50;
this.Promise = options.Promise;

this[STATUS] = new Status(this.options);
Expand Down
30 changes: 15 additions & 15 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ test('Works with callback functions that fail', (t) => {

test('Breaker opens after a configurable number of failures', (t) => {
t.plan(2);
const breaker = cb(passFail, { maxFailures: 1 });
const breaker = cb(passFail, { errorThresholdPercentage: 10 });

breaker.fire(-1)
.then(t.fail)
Expand All @@ -197,7 +197,7 @@ test('Breaker resets after a configurable amount of time', (t) => {
t.plan(1);
const fails = -1;
const resetTimeout = 100;
const breaker = cb(passFail, { maxFailures: 1, resetTimeout });
const breaker = cb(passFail, { errorThresholdPercentage: 1, resetTimeout });

breaker.fire(fails)
.catch(() => {
Expand All @@ -213,7 +213,7 @@ test('Breaker resets after a configurable amount of time', (t) => {

test.skip('Breaker status reflects open state', (t) => {
t.plan(1);
const breaker = cb(passFail, {maxFailures: 0, resetTimeout: 100});
const breaker = cb(passFail, {errorThresholdPercentage: 0, resetTimeout: 100});
breaker.fire(-1)
.then(t.fail)
.catch(() => t.ok(breaker.status.window[0].isCircuitBreakerOpen))
Expand All @@ -224,7 +224,7 @@ test('Breaker resets for circuits with a fallback function', (t) => {
t.plan(2);
const fails = -1;
const resetTimeout = 100;
const breaker = cb(passFail, { maxFailures: 1, resetTimeout });
const breaker = cb(passFail, { errorThresholdPercentage: 1, resetTimeout });
breaker.fallback((x) => x * 2);

breaker.on('fallback', (result) => {
Expand All @@ -248,7 +248,7 @@ test('Executes fallback action, if one exists, when breaker is open', (t) => {
t.plan(1);
const fails = -1;
const expected = 100;
const breaker = cb(passFail, { maxFailures: 1 });
const breaker = cb(passFail, { errorThresholdPercentage: 1 });
breaker.fallback(() => expected);
breaker.fire(fails)
.then(() => {
Expand All @@ -262,7 +262,7 @@ test('Executes fallback action, if one exists, when breaker is open', (t) => {
test('Passes arguments to the fallback function', (t) => {
t.plan(1);
const fails = -1;
const breaker = cb(passFail, { maxFailures: 1 });
const breaker = cb(passFail, { errorThresholdPercentage: 1 });
breaker.on('fallback', (result) => {
t.equals(result, fails, 'fallback received expected parameters');
t.end();
Expand All @@ -273,7 +273,7 @@ test('Passes arguments to the fallback function', (t) => {

test('Returns self from fallback()', (t) => {
t.plan(1);
cb(passFail, { maxFailures: 1 })
cb(passFail, { errorThresholdPercentage: 1 })
.fallback(() => {})
.fire(1)
.then((result) => {
Expand Down Expand Up @@ -324,7 +324,7 @@ test('CircuitBreaker emits failure when falling back', (t) => {

test('CircuitBreaker status', (t) => {
t.plan(11);
const breaker = cb(passFail, { maxFailures: 1 });
const breaker = cb(passFail, { errorThresholdPercentage: 1 });
const deepEqual = (t, expected) => (actual) => t.deepEqual(actual, expected, 'expected status values');

Fidelity.all([
Expand Down Expand Up @@ -401,7 +401,7 @@ test('CircuitBreaker status listeners', (t) => {

test('CircuitBreaker fallback event', (t) => {
t.plan(1);
const breaker = cb(passFail, {maxFailures: 0});
const breaker = cb(passFail, {errorThresholdPercentage: 0});
breaker.fallback((x) => x);
breaker.on('fallback', (value) => {
t.equal(value, -1, 'fallback value received');
Expand All @@ -413,7 +413,7 @@ test('CircuitBreaker fallback event', (t) => {
test('CircuitBreaker events', (t) => {
t.plan(41);
const options = {
maxFailures: 1,
errorThresholdPercentage: 1,
timeout: 500,
resetTimeout: 500
};
Expand Down Expand Up @@ -520,7 +520,7 @@ test('CircuitBreaker events', (t) => {
test('circuit halfOpen', (t) => {
t.plan(8);
const options = {
maxFailures: 1,
errorThresholdPercentage: 1,
resetTimeout: 100
};

Expand Down Expand Up @@ -559,7 +559,7 @@ test('circuit halfOpen', (t) => {
test('CircuitBreaker fallback as a rejected promise', (t) => {
t.plan(1);
const options = {
maxFailures: 1,
errorThresholdPercentage: 1,
resetTimeout: 100
};
const input = -1;
Expand All @@ -579,7 +579,7 @@ test('CircuitBreaker fallback as a rejected promise', (t) => {
test('CircuitBreaker fallback as a CircuitBreaker', (t) => {
t.plan(1);
const options = {
maxFailures: 1,
errorThresholdPercentage: 1,
resetTimeout: 100
};

Expand All @@ -595,7 +595,7 @@ test('CircuitBreaker fallback as a CircuitBreaker', (t) => {
test('CircuitBreaker fallback as a CircuitBreaker that fails', (t) => {
t.plan(1);
const options = {
maxFailures: 1,
errorThresholdPercentage: 1,
resetTimeout: 100
};

Expand All @@ -611,7 +611,7 @@ test('CircuitBreaker fallback as a CircuitBreaker that fails', (t) => {
test('CircuitBreaker fallback as a CircuitBreaker', (t) => {
t.plan(1);
const options = {
maxFailures: 1,
errorThresholdPercentage: 1,
resetTimeout: 100
};

Expand Down

0 comments on commit be65d3b

Please sign in to comment.