Skip to content

Commit

Permalink
test: improve circuit.shutdown() test
Browse files Browse the repository at this point in the history
  • Loading branch information
lance committed Apr 5, 2019
1 parent dd111ef commit 6841abc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ class CircuitBreaker extends EventEmitter {
this.options.rollingCountBuckets = options.rollingCountBuckets || 10;
this.options.rollingPercentilesEnabled =
options.rollingPercentilesEnabled !== false;
this.options.capacity = Number.isInteger(options.capacity) ? options.capacity : Number.MAX_SAFE_INTEGER;
this.options.capacity = Number.isInteger(options.capacity)
? options.capacity : Number.MAX_SAFE_INTEGER;
this.options.errorFilter = options.errorFilter || (_ => false);

this.semaphore = new Semaphore(this.options.capacity);

this[VOLUME_THRESHOLD] = Number.isInteger(options.volumeThreshold) ? options.volumeThreshold : 0;
this[VOLUME_THRESHOLD] = Number.isInteger(options.volumeThreshold)
? options.volumeThreshold : 0;
this[WARMING_UP] = options.allowWarmUp === true;
this[STATUS] = new Status(this.options);
this[STATE] = CLOSED;
Expand Down
10 changes: 8 additions & 2 deletions test/circuit-shutdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ test('EventEmitter max listeners', t => {
});

test('Circuit shuts down properly', t => {
t.plan(3);
t.plan(5);
const breaker = circuit(passFail);
t.ok(breaker.fire(1), 'breaker is active');
breaker.shutdown();
t.ok(breaker.isShutdown, 'breaker is shutdown');
t.notOk(breaker.enabled, 'breaker has been disabled');
t.end();
breaker.fire(1)
.then(t.fail)
.catch(err => {
t.equals('ESHUTDOWN', err.code);
t.equals('The circuit has been shutdown.', err.message);
t.end();
});
});

0 comments on commit 6841abc

Please sign in to comment.