From 8d6e09fdab02064163f0d02802af12dbc07bcd18 Mon Sep 17 00:00:00 2001 From: "Mark S. Lewis" Date: Thu, 13 Sep 2018 09:45:40 +0100 Subject: [PATCH] FABN-919: Add error messages to event strategy failures Change-Id: I85573e32c78e8c2089eccb68801a7919bee994cb Signed-off-by: Mark S. Lewis --- .../lib/impl/event/allfortxstrategy.js | 2 +- .../lib/impl/event/anyfortxstrategy.js | 2 +- fabric-network/test/impl/event/eventstrategy.js | 16 +++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/fabric-network/lib/impl/event/allfortxstrategy.js b/fabric-network/lib/impl/event/allfortxstrategy.js index 9cc65c662a..12f5193386 100644 --- a/fabric-network/lib/impl/event/allfortxstrategy.js +++ b/fabric-network/lib/impl/event/allfortxstrategy.js @@ -35,7 +35,7 @@ class AllForTxStrategy extends AbstractEventStrategy { if (counts.success > 0) { successFn(); } else { - failFn(); + failFn(new Error('No successful events received')); } } } diff --git a/fabric-network/lib/impl/event/anyfortxstrategy.js b/fabric-network/lib/impl/event/anyfortxstrategy.js index 494a19959f..30fa586226 100644 --- a/fabric-network/lib/impl/event/anyfortxstrategy.js +++ b/fabric-network/lib/impl/event/anyfortxstrategy.js @@ -34,7 +34,7 @@ class AnyForTxStrategy extends AbstractEventStrategy { if (counts.success > 0) { successFn(); } else if (isAllResponsesReceived) { - failFn(); + failFn(new Error('No successful events received')); } } } diff --git a/fabric-network/test/impl/event/eventstrategy.js b/fabric-network/test/impl/event/eventstrategy.js index f4bfb4f042..610732897e 100644 --- a/fabric-network/test/impl/event/eventstrategy.js +++ b/fabric-network/test/impl/event/eventstrategy.js @@ -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', () => { @@ -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; }); }); @@ -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; }); @@ -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; }); }); });