-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into ethereum-adapter
- Loading branch information
Showing
6 changed files
with
280 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
# | ||
# 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. | ||
# | ||
|
||
# Exit on first error, print all commands. | ||
set -e | ||
set -o pipefail | ||
|
||
# Bootstrap the project | ||
npm run bootstrap | ||
|
||
# Run linting, license check and unit tests | ||
npm test | ||
|
||
echo "---- Running Integration test for adaptor ${BENCHMARK}" | ||
cd ./packages/caliper-tests-integration/ | ||
npm run run_tests_direct |
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
191 changes: 191 additions & 0 deletions
191
packages/caliper-core/test/rate-control/fixedBacklog.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,191 @@ | ||
/* | ||
* 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 rewire = require('rewire'); | ||
const FixedBacklog = rewire('../../lib/rate-control/fixedBacklog'); | ||
|
||
const chai = require('chai'); | ||
chai.should(); | ||
const sinon = require('sinon'); | ||
|
||
describe ('fixedBacklog controller implementation', () => { | ||
|
||
let controller; | ||
let opts = { | ||
unfinished_per_client: 30, | ||
sleep_time: 40 | ||
}; | ||
|
||
describe ('#init', () => { | ||
|
||
it ('should set a default sleep time if no sleep time specified', () => { | ||
controller = new FixedBacklog.createRateController({}); | ||
controller.init(); | ||
controller.sleep_time.should.equal(100); | ||
}); | ||
|
||
it ('should set the sleep time if specified', () => { | ||
controller = new FixedBacklog.createRateController(opts); | ||
controller.init(); | ||
controller.sleep_time.should.equal(40); | ||
}); | ||
|
||
it ('should set a default transaction backlog for multiple clients if not specified', () => { | ||
controller = new FixedBacklog.createRateController({}); | ||
controller.init(); | ||
controller.unfinished_per_client.should.equal(10); | ||
}); | ||
|
||
it ('should set the transaction backlog for multiple clients if specified', () => { | ||
controller = new FixedBacklog.createRateController(opts); | ||
controller.init(); | ||
controller.unfinished_per_client.should.equal(30); | ||
}); | ||
|
||
}); | ||
|
||
describe ('#applyRateControl', () => { | ||
|
||
let sleepStub; | ||
|
||
beforeEach(() => { | ||
sleepStub = sinon.stub(); | ||
FixedBacklog.__set__('Sleep', sleepStub); | ||
|
||
controller = new FixedBacklog.createRateController(opts); | ||
controller.init(); | ||
}); | ||
|
||
it ('should sleep if resultStats.length < 2', () => { | ||
controller.applyRateControl(null, 1, [], []); | ||
sinon.assert.calledOnce(sleepStub); | ||
sinon.assert.calledWith(sleepStub, 40); | ||
}); | ||
|
||
it ('should sleep if no successful results are available', () => { | ||
controller.applyRateControl(null, 1, [], [{}]); | ||
sinon.assert.calledOnce(sleepStub); | ||
sinon.assert.calledWith(sleepStub, 40); | ||
}); | ||
|
||
it ('should sleep if no delay results are available', () => { | ||
controller.applyRateControl(null, 1, [], [{}]); | ||
sinon.assert.calledOnce(sleepStub); | ||
sinon.assert.calledWith(sleepStub, 40); | ||
}); | ||
|
||
it ('should not sleep if backlog transaction is below target', () => { | ||
let idx = 50; | ||
let currentResults = []; | ||
let item = { | ||
succ: 5, | ||
length: 30, | ||
delay: { | ||
sum: 5 | ||
} | ||
}; | ||
const resultStats = []; | ||
resultStats.push(item); | ||
resultStats.push(item); | ||
|
||
controller.applyRateControl(null, idx, currentResults, resultStats); | ||
sinon.assert.notCalled(sleepStub); | ||
}); | ||
|
||
it ('should sleep if backlog transaction is at or above target', () => { | ||
let idx = 50; | ||
let currentResults = []; | ||
let item = { | ||
succ: 5, | ||
length: 5, | ||
delay: { | ||
sum: 5 | ||
} | ||
}; | ||
const resultStats = []; | ||
resultStats.push(item); | ||
resultStats.push(item); | ||
|
||
controller.applyRateControl(null, idx, currentResults, resultStats); | ||
|
||
sinon.assert.calledOnce(sleepStub); | ||
}); | ||
|
||
it ('should sleep for a count of the load error and the current average delay', () => { | ||
let idx = 50; | ||
let currentResults = []; | ||
let item = { | ||
succ: 5, | ||
length: 5, | ||
delay: { | ||
sum: 5 | ||
} | ||
}; | ||
const resultStats = []; | ||
resultStats.push(item); | ||
resultStats.push(item); | ||
|
||
controller.applyRateControl(null, idx, currentResults, resultStats); | ||
|
||
const completeTransactions = resultStats[0].length - currentResults.length; | ||
const unfinshed = idx - completeTransactions; | ||
|
||
const error = unfinshed - 30; | ||
const avDelay = ((resultStats[0].delay.sum)/completeTransactions)*1000; | ||
|
||
sinon.assert.calledOnce(sleepStub); | ||
sinon.assert.calledWith(sleepStub, error*avDelay); | ||
}); | ||
|
||
it('should log the backlog error as a debug message', () => { | ||
|
||
const FakeLogger = { | ||
debug : () => {}, | ||
error: () => {} | ||
}; | ||
|
||
let debugStub = sinon.stub(FakeLogger, 'debug'); | ||
FixedBacklog.__set__('Logger', FakeLogger); | ||
|
||
let idx = 50; | ||
let currentResults = []; | ||
let item = { | ||
succ: 5, | ||
length: 5, | ||
delay: { | ||
sum: 5 | ||
} | ||
}; | ||
const resultStats = []; | ||
resultStats.push(item); | ||
resultStats.push(item); | ||
|
||
controller.applyRateControl(null, idx, currentResults, resultStats); | ||
|
||
const completeTransactions = resultStats[0].length - currentResults.length; | ||
const unfinshed = idx - completeTransactions; | ||
|
||
const error = unfinshed - 30; | ||
const message = "Backlog error: " + error; | ||
|
||
sinon.assert.calledOnce(debugStub); | ||
sinon.assert.calledWith(debugStub, message); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
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
58 changes: 58 additions & 0 deletions
58
packages/caliper-tests-integration/scripts/run-tests-direct.sh
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,58 @@ | ||
#!/bin/bash | ||
# | ||
# 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. | ||
# | ||
|
||
# Exit on first error, print all commands. | ||
set -ev | ||
set -o pipefail | ||
|
||
# Set ARCH | ||
ARCH=`uname -m` | ||
|
||
# Grab the parent (root) directory. | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" | ||
|
||
# Switch into the integration tests directory to access required npm run commands | ||
cd "${DIR}" | ||
|
||
# Barf if we don't recognize this test adaptor. | ||
if [[ "${BENCHMARK}" = "" ]]; then | ||
echo You must set BENCHMARK to one of the desired test adaptors 'composer|fabric' | ||
echo For example: | ||
echo export BENCHMARK=fabric | ||
exit 1 | ||
fi | ||
|
||
# Run benchmark adaptor | ||
if [[ "${BENCHMARK}" == "composer" ]]; then | ||
node ../caliper-cli/caliper.js benchmark run --caliper-benchconfig benchmark/composer/config.yaml --caliper-networkconfig network/fabric-v1.3/2org1peercouchdb/composer.json --caliper-workspace ../caliper-samples/ | ||
rc=$? | ||
exit $rc; | ||
elif [[ "${BENCHMARK}" == "fabric" ]]; then | ||
# Run with channel creation using a createChannelTx in couchDB, using a Gateway | ||
|
||
node ../caliper-cli/caliper.js benchmark run --caliper-benchconfig benchmark/simple/config.yaml --caliper-networkconfig network/fabric-v1.4.1/2org1peercouchdb/fabric-node.yaml --caliper-workspace ../caliper-samples/ --caliper-fabric-usegateway | ||
rc=$? | ||
if [[ $rc != 0 ]]; then | ||
exit $rc; | ||
else | ||
# Run with channel creation using an existing tx file in LevelDB, using a low level Caliper client | ||
node ../caliper-cli/caliper.js benchmark run --caliper-benchconfig benchmark/simple/config.yaml --caliper-networkconfig network/fabric-v1.4/2org1peergoleveldb/fabric-go.yaml --caliper-workspace ../caliper-samples/ | ||
rc=$? | ||
exit $rc; | ||
fi | ||
else | ||
echo "Unknown target benchmark ${BENCHMARK}" | ||
exit 1 | ||
fi |