Skip to content

Commit

Permalink
FABN-919: Add error messages to event strategy failures
Browse files Browse the repository at this point in the history
Change-Id: I85573e32c78e8c2089eccb68801a7919bee994cb
Signed-off-by: Mark S. Lewis <[email protected]>
  • Loading branch information
bestbeforetoday committed Sep 13, 2018
1 parent 961d34b commit 8d6e09f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion fabric-network/lib/impl/event/allfortxstrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AllForTxStrategy extends AbstractEventStrategy {
if (counts.success > 0) {
successFn();
} else {
failFn();
failFn(new Error('No successful events received'));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion fabric-network/lib/impl/event/anyfortxstrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AnyForTxStrategy extends AbstractEventStrategy {
if (counts.success > 0) {
successFn();
} else if (isAllResponsesReceived) {
failFn();
failFn(new Error('No successful events received'));
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions fabric-network/test/impl/event/eventstrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ describe('Event Strategy Implementations', () => {
it('calls success callback on second event of two expected events', () => {
strategy.eventReceived(stubSuccessFn, stubFailFn);
strategy.eventReceived(stubSuccessFn, stubFailFn);
expect(stubSuccessFn.called, 'successFn').to.be.true;
expect(stubSuccessFn.calledOnce, 'successFn').to.be.true;
expect(stubFailFn.notCalled, 'failFn').to.be.true;
});

it('calls success callback on error then event of two expected events', () => {
strategy.errorReceived(stubSuccessFn, stubFailFn);
strategy.eventReceived(stubSuccessFn, stubFailFn);
sinon.assert.called(stubSuccessFn);
sinon.assert.notCalled(stubFailFn);
expect(stubSuccessFn.calledOnce, 'successFn').to.be.true;
expect(stubFailFn.notCalled, 'failFn').to.be.true;
});

it('does not call callbacks on first error of two expected events', () => {
Expand All @@ -149,13 +149,14 @@ describe('Event Strategy Implementations', () => {
strategy.errorReceived(stubSuccessFn, stubFailFn);
strategy.errorReceived(stubSuccessFn, stubFailFn);
expect(stubSuccessFn.notCalled, 'successFn').to.be.true;
expect(stubFailFn.called, 'failFn').to.be.true;
expect(stubFailFn.calledOnce, 'failFn').to.be.true;
expect(stubFailFn.calledWith(sinon.match.instanceOf(Error)), 'failFn(Error)').to.be.true;
});

it('calls success callback on event then error of two expected events', () => {
strategy.errorReceived(stubSuccessFn, stubFailFn);
strategy.eventReceived(stubSuccessFn, stubFailFn);
expect(stubSuccessFn.called, 'successFn').to.be.true;
expect(stubSuccessFn.calledOnce, 'successFn').to.be.true;
expect(stubFailFn.notCalled, 'failFn').to.be.true;
});
});
Expand All @@ -171,7 +172,7 @@ describe('Event Strategy Implementations', () => {

it('calls success callback on first event of two expected events', () => {
strategy.eventReceived(stubSuccessFn, stubFailFn);
expect(stubSuccessFn.called, 'successFn').to.be.true;
expect(stubSuccessFn.calledOnce, 'successFn').to.be.true;
expect(stubFailFn.notCalled, 'failFn').to.be.true;
});

Expand All @@ -192,7 +193,8 @@ describe('Event Strategy Implementations', () => {
strategy.errorReceived(stubSuccessFn, stubFailFn);
strategy.errorReceived(stubSuccessFn, stubFailFn);
expect(stubSuccessFn.notCalled, 'successFn').to.be.true;
expect(stubFailFn.called, 'failFn').to.be.true;
expect(stubFailFn.calledOnce, 'failFn').to.be.true;
expect(stubFailFn.calledWith(sinon.match.instanceOf(Error)), 'failFn(Error)').to.be.true;
});
});
});

0 comments on commit 8d6e09f

Please sign in to comment.