-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes caliper hang of unfinished transactions (#1342)
This addresses a long standing issue in caliper where a round will hang waiting for unfinished transactions that have actually finished but not been recorded. It also addresses an issue where the fabric connectors try to change the time_create value of a TxStatus but in fact actually doesn't change the creation time. closes #1068 closes #1340 Signed-off-by: D <[email protected]>
- Loading branch information
Showing
9 changed files
with
148 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
packages/caliper-core/test/core/transaction-statistics-collector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
chai.should(); | ||
|
||
const TransactionStatisticsCollector = require('../../lib/common/core/transaction-statistics-collector'); | ||
const TxStatus = require('../../lib/common/core/transaction-status'); | ||
|
||
describe('the transaction statistics collector', () => { | ||
const createSuccessfulTxStatus = (creationTimeAfterRoundStart) => { | ||
const txStatus = new TxStatus('id'); | ||
txStatus.SetTimeCreate(txStatsCollector.getRoundStartTime() + creationTimeAfterRoundStart); | ||
txStatus.SetStatusSuccess(); | ||
return txStatus; | ||
}; | ||
|
||
let txStatsCollector; | ||
beforeEach(() => { | ||
txStatsCollector = new TransactionStatisticsCollector(1,1,''); | ||
txStatsCollector.activate(); | ||
}) | ||
|
||
it('should register as finished a single finished transaction while active irrespective of time of creation', () => { | ||
txStatsCollector.txSubmitted(3); | ||
|
||
// test if it finishes after the round start time | ||
txStatsCollector.txFinished(createSuccessfulTxStatus(60000)); | ||
txStatsCollector.getTotalFinishedTx().should.equal(1); | ||
|
||
// test if it finishes when the round started | ||
txStatsCollector.txFinished(createSuccessfulTxStatus(0)); | ||
txStatsCollector.getTotalFinishedTx().should.equal(2); | ||
|
||
// test if it finishes before the round start time | ||
txStatsCollector.txFinished(createSuccessfulTxStatus(-60000)); | ||
txStatsCollector.getTotalFinishedTx().should.equal(3); | ||
|
||
}); | ||
|
||
it('should register multiple transactions as finished while active irrespective of time of creation', () => { | ||
txStatsCollector.txSubmitted(3); | ||
txStatsCollector.txFinished([createSuccessfulTxStatus(60000), createSuccessfulTxStatus(0), createSuccessfulTxStatus(-60000)]); | ||
txStatsCollector.getTotalFinishedTx().should.equal(3); | ||
}); | ||
|
||
it('should record the transaction statistics if the status was created after the round started', () => { | ||
txStatsCollector.txSubmitted(1); | ||
txStatsCollector.getTotalSuccessfulTx().should.equal(0); | ||
txStatsCollector.txFinished(createSuccessfulTxStatus(60000)); | ||
txStatsCollector.getTotalSuccessfulTx().should.equal(1); | ||
}); | ||
|
||
it('should record the transaction statistics if the status was created at the same time the round started', () => { | ||
txStatsCollector.txSubmitted(1); | ||
txStatsCollector.getTotalSuccessfulTx().should.equal(0); | ||
txStatsCollector.txFinished(createSuccessfulTxStatus(0)); | ||
txStatsCollector.getTotalSuccessfulTx().should.equal(1); | ||
}); | ||
|
||
it('should NOT record the transaction statistics if the status was created before the round started', () => { | ||
txStatsCollector.txSubmitted(1); | ||
txStatsCollector.getTotalSuccessfulTx().should.equal(0); | ||
txStatsCollector.txFinished(createSuccessfulTxStatus(-60000)); | ||
txStatsCollector.getTotalSuccessfulTx().should.equal(0); | ||
}); | ||
|
||
it('should include only the status results that were created on of after the round started', () => { | ||
txStatsCollector.txSubmitted(3); | ||
txStatsCollector.txFinished([createSuccessfulTxStatus(60000), createSuccessfulTxStatus(0), createSuccessfulTxStatus(-60000)]); | ||
txStatsCollector.getTotalSuccessfulTx().should.equal(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
chai.should(); | ||
|
||
const TxStatus = require('../../lib/common/core/transaction-status'); | ||
|
||
describe('the transaction status', () => { | ||
it('should create a default time creation', () => { | ||
const txStatus = new TxStatus(); | ||
txStatus.GetTimeCreate().should.be.greaterThan(0); | ||
}); | ||
|
||
it('should allow changing of the default time creation', () => { | ||
const txStatus = new TxStatus(); | ||
const orgTimeCreate = txStatus.GetTimeCreate(); | ||
const newTimeCreate = Date.now() + 60000; | ||
txStatus.SetTimeCreate(newTimeCreate); | ||
txStatus.GetTimeCreate().should.not.equal(orgTimeCreate); | ||
txStatus.GetTimeCreate().should.equal(newTimeCreate); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters