Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into ethereum-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
russanto committed Aug 12, 2019
2 parents f670884 + 424e98c commit 083b4fe
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ before_install: |
set -o pipefail
npm install -g @alrra/travis-scripts
script: ./.travis/script.sh
script: ./.travis/avoid_verdaccio.sh

cache:
directories:
Expand Down
28 changes: 28 additions & 0 deletions .travis/avoid_verdaccio.sh
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
2 changes: 1 addition & 1 deletion packages/caliper-core/lib/rate-control/fixedBacklog.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class FixedBacklog extends RateInterface {
const error = unfinished - this.unfinished_per_client;

// Sleep for a count of the load error and the current average delay
Logger.info('Backlog error: ' + error);
Logger.debug('Backlog error: ' + error);
await Sleep(error * avDelay);
}

Expand Down
191 changes: 191 additions & 0 deletions packages/caliper-core/test/rate-control/fixedBacklog.js
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);

});

});

});
1 change: 1 addition & 0 deletions packages/caliper-tests-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"install_cli": "./scripts/install-packages.sh",
"e2e_install": "npm run cleanup && npm run start_verdaccio && npm run publish_packages && npm run install_cli && npm run cleanup",
"run_tests": "./scripts/run-tests.sh",
"run_tests_direct": "./scripts/run-tests-direct.sh",
"stop_verdaccio": "PM2_HOME=.pm2 pm2 stop verdaccio || true",
"pretest": "npm run licchk",
"licchk": "license-check-and-add",
Expand Down
58 changes: 58 additions & 0 deletions packages/caliper-tests-integration/scripts/run-tests-direct.sh
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

0 comments on commit 083b4fe

Please sign in to comment.