Skip to content

Commit

Permalink
[FABN-1308] Enable checkpointing when start or end block are given (#51)
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Grace <[email protected]>
  • Loading branch information
liam-grace authored and andrew-coleman committed Dec 13, 2019
1 parent 864bd5d commit 6eb90b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions fabric-network/src/impl/event/abstracteventlistener.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ class AbstractEventListener {
if (!this.getCheckpointer()) {
logger.error('Opted to use checkpointing without defining a checkpointer');
}
if ((this.clientOptions.startBlock !== null) && (this.clientOptions.startBlock !== undefined) ||
if ((this.clientOptions.startBlock !== null) && (this.clientOptions.startBlock !== undefined) &&
(this.clientOptions.endBlock !== null) && (this.clientOptions.endBlock !== undefined)) {
logger.debug('startBlock and/or endBlock were given. Disabling event replay');
logger.debug('startBlock and endBlock were given. Disabling event replay');
this.options.replay = false;
}
}
Expand Down
18 changes: 15 additions & 3 deletions fabric-network/test/impl/event/abstracteventlistener.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,25 +195,37 @@ describe('AbstractEventListener', () => {
sinon.assert.notCalled(eventHub.disconnect);
});

it('should set replay to false if startBlock is set', async () => {
it('should allow replay if startBlock is set', async () => {
const eventHub = sandbox.createStubInstance(ChannelEventHub);
eventHub.isconnected.returns(true);
eventHub.isFiltered.returns(false);
testListener.eventHub = eventHub;
testListener.options.replay = true;
testListener.clientOptions.startBlock = 0;
await testListener.register();
expect(testListener.options.replay).to.be.false;
expect(testListener.options.replay).to.be.true;
});

it('should set replay to false if endBlock is set', async () => {
it('should allow replay if endBlock is set', async () => {
const eventHub = sandbox.createStubInstance(ChannelEventHub);
eventHub.isconnected.returns(true);
eventHub.isFiltered.returns(false);
testListener.eventHub = eventHub;
testListener.options.replay = true;
testListener.clientOptions.endBlock = 10;
await testListener.register();
expect(testListener.options.replay).to.be.true;
});

it('should not allow replay if both start and end block are set', async () => {
const eventHub = sandbox.createStubInstance(ChannelEventHub);
eventHub.isconnected.returns(true);
eventHub.isFiltered.returns(false);
testListener.eventHub = eventHub;
testListener.options.replay = true;
testListener.clientOptions.startBlock = 0;
testListener.clientOptions.endBlock = 10;
await testListener.register();
expect(testListener.options.replay).to.be.false;
});
});
Expand Down

0 comments on commit 6eb90b8

Please sign in to comment.