Skip to content

Commit

Permalink
Merge pull request #48 from fed135/next
Browse files Browse the repository at this point in the history
[Release] v1.7.1
  • Loading branch information
fed135 authored Nov 14, 2018
2 parents 921739f + 986835c commit d072f63
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ha-store",
"version": "1.7.0",
"version": "1.7.1",
"description": "Efficient data fetching",
"main": "src/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/breaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {tween} = require('./utils.js');
/* Methods -------------------------------------------------------------------*/

function breaker(config, emitter) {
config = config || {};
let active = false;
const circuitError = new Error('Service unavailable (circuit-breaker)');
let timer = null;
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HaStore extends EventEmitter {
this.setMaxListeners(Infinity);
}

this.breaker = breaker(this.config.breaker, this);
this.breaker = breaker(this.config, this);

this.queue = queue(
this.config,
Expand Down
38 changes: 25 additions & 13 deletions tests/unit/breaker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,44 @@ const config = {
};

/* Tests ---------------------------------------------------------------------*/
const varToString = (value) => {
return typeof value === 'object'
? JSON.stringify(value)
: `${value}`;
}

describe('breaker', () => {
let testCircuit;
let testEmitter;

const assertIsInactive = (status) => expect(status).to.be.deep.equal({active: false, step: 0, ttl: undefined});

it('should be a noop if no configuration is supplied', () => {
const stubbedEmitter = new EventEmitter();
sinon.spy(stubbedEmitter, 'emit');
[
{breaker: null},
undefined,
null,
{},
].forEach((config)=>(
it(`should be a noop if no configuration (${varToString(config)}) is supplied`, () => {
const stubbedEmitter = new EventEmitter();
sinon.spy(stubbedEmitter, 'emit');

const testBreaker = breaker({breaker: null}, stubbedEmitter);
assertIsInactive(testBreaker.status());
const testBreaker = breaker(config, stubbedEmitter);
assertIsInactive(testBreaker.status());

testBreaker.openCircuit();
assertIsInactive(testBreaker.status());
testBreaker.openCircuit();
assertIsInactive(testBreaker.status());

testBreaker.restoreCircuit();
assertIsInactive(testBreaker.status());
testBreaker.restoreCircuit();
assertIsInactive(testBreaker.status());

testBreaker.closeCircuit();
assertIsInactive(testBreaker.status());
testBreaker.closeCircuit();
assertIsInactive(testBreaker.status());

sinon.assert.notCalled(stubbedEmitter.emit);
sinon.assert.notCalled(stubbedEmitter.emit);
})
));

});

describe('#closeCircuit', () => {
beforeEach(() => {
Expand Down

0 comments on commit d072f63

Please sign in to comment.