Skip to content

Commit

Permalink
Enable sys test v1 (hyperledger-archives#558)
Browse files Browse the repository at this point in the history
* Enable V1 system tests

Signed-off-by: Dave Kelsey <[email protected]>

* update build to split system tests for v1

Signed-off-by: Dave Kelsey <[email protected]>

* fix the issue where startsWith isn’t in the web env

Signed-off-by: Dave Kelsey <[email protected]>

* address web system test failure

Signed-off-by: Dave Kelsey <[email protected]>

* timeout failure on deploy, need to adjust timeout

Signed-off-by: Dave Kelsey <[email protected]>
  • Loading branch information
Dave Kelsey authored Mar 23, 2017
1 parent 9be4dfc commit 9caf34c
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ matrix:
- env: SYSTEST=embedded FC_TASK=systest
- env: SYSTEST=web FC_TASK=systest
- env: SYSTEST=hlf SYSTEST_HLF=hlf FC_TASK=systest
- env: SYSTEST=hlf SYSTEST_HLF=ibm FC_TASK=systest
- env: SYSTEST=hlfv1-1 SYSTEST_HLF=hlf FC_TASK=systest
- env: SYSTEST=hlfv1-2 SYSTEST_HLF=hlf FC_TASK=systest
dist: trusty
addons:
apt:
Expand Down
9 changes: 5 additions & 4 deletions packages/composer-connector-hlfv1/lib/hlfconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class HLFConnection extends Connection {
if (response.status !== 'SUCCESS') {
throw new Error(`Failed to commit transaction '${finalTxId}' with response status '${response.status}'`);
}
return this._waitForEvents(finalTxId);
return this._waitForEvents(finalTxId, this.connectOptions.deployWaitTime);

})
.then(() => {
Expand Down Expand Up @@ -630,7 +630,7 @@ class HLFConnection extends Connection {
if (response.status !== 'SUCCESS') {
throw new Error(`Failed to commit transaction '${txId}' with response status '${response.status}'`);
}
return this._waitForEvents(txId);
return this._waitForEvents(txId, this.connectOptions.invokeWaitTime);
})
.catch((error) => {
LOG.error(method, error);
Expand Down Expand Up @@ -725,17 +725,18 @@ class HLFConnection extends Connection {
/**
* wait for events from the peers associated with the provided transaction id.
* @param {string} txId the transaction id to listen for events on
* @param {number} waitTime the time to wait in seconds for an event response
* @returns {Promise} A promise which resolves when all the events are received or rejected
* if an event is not received within the given timeout period
* @memberOf HLFConnection
*/
_waitForEvents(txId) {
_waitForEvents(txId, waitTime) {
let eventPromises = [];
this.eventHubs.forEach((eh) => {
let txPromise = new Promise((resolve, reject) => {
const handle = setTimeout(() => {
reject(new Error(`Failed to receive commit notification for transaction '${txId}' within the timeout period`));
}, this.connectOptions.invokeWaitTime * 1000);
}, waitTime * 1000);
eh.registerTxEvent(txId.toString(), (tx, code) => {
clearTimeout(handle);
eh.unregisterTxEvent(txId);
Expand Down
99 changes: 99 additions & 0 deletions packages/composer-connector-hlfv1/test/hlfconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,56 @@ describe('HLFConnection', () => {
}).should.throw(/businessNetwork not specified/);
});

it('should request an event timeout based on connection settings', () => {
connectOptions = {
orderers: [
'grpc://localhost:7050'
],
peers: [
'grpc://localhost:7051'
],
events: [
'grpc://localhost:7053'
],
ca: 'http://localhost:7054',
keyValStore: '/tmp/hlfabric1',
channel: 'testchainid',
mspid: 'suchmsp',
deployWaitTime: 39,
invokeWaitTime: 63,
};
connection = new HLFConnection(mockConnectionManager, 'hlfabric1', 'org.acme.biznet', connectOptions, mockClient, mockChain, [mockEventHub], mockCAClient);
// This is the generated nonce.
sandbox.stub(utils, 'getNonce').returns('11111111-1111-1111-1111-111111111111');
// This is the deployment proposal and response (from the peers).
const proposalResponses = [{
response: {
status: 200
}
}];
const proposal = { proposal: 'i do' };
const header = { header: 'gooooal' };
const response = {
status: 'SUCCESS'
};
// This is the generated transaction
mockChain.buildTransactionID.returns('00000000-0000-0000-0000-000000000000');
// mock out getUserContext version in case we need to return to using this one
mockChain.buildTransactionID_getUserContext.resolves('00000000-0000-0000-0000-000000000000');
mockChain.sendInstallProposal.resolves([ proposalResponses, proposal, header ]);
mockChain.sendInstantiateProposal.resolves([ proposalResponses, proposal, header ]);
mockChain.sendTransaction.withArgs({ proposalResponses: proposalResponses, proposal: proposal, header: header }).resolves(response);
// This is the event hub response.
sandbox.stub(global, 'setTimeout').yields();
return connection.deploy(mockSecurityContext, false, mockBusinessNetwork)
.catch(() => {
sinon.assert.calledWith(global.setTimeout, sinon.match.func, sinon.match.number);
sinon.assert.calledWith(global.setTimeout, sinon.match.func, connectOptions.deployWaitTime * 1000);
});
});

it('should deploy the business network', () => {
sandbox.stub(global, 'setTimeout');
// This is the generated nonce.
sandbox.stub(utils, 'getNonce').returns('11111111-1111-1111-1111-111111111111');
// This is the deployment proposal and response (from the peers).
Expand Down Expand Up @@ -877,6 +926,56 @@ describe('HLFConnection', () => {
.should.be.rejectedWith(/such error/);
});

it('should set the timeout to value specified in connection profile', () => {
connectOptions = {
orderers: [
'grpc://localhost:7050'
],
peers: [
'grpc://localhost:7051'
],
events: [
'grpc://localhost:7053'
],
ca: 'http://localhost:7054',
keyValStore: '/tmp/hlfabric1',
channel: 'testchainid',
mspid: 'suchmsp',
deployWaitTime: 39,
invokeWaitTime: 63,
};
connection = new HLFConnection(mockConnectionManager, 'hlfabric1', 'org.acme.biznet', connectOptions, mockClient, mockChain, [mockEventHub], mockCAClient);
// This is the generated nonce.
sandbox.stub(utils, 'getNonce').returns('11111111-1111-1111-1111-111111111111');
// This is the generated transaction
mockChain.buildTransactionID.returns('00000000-0000-0000-0000-000000000000');
// mock out getUserContext version in case we need to return to using this one
mockChain.buildTransactionID_getUserContext.resolves('00000000-0000-0000-0000-000000000000');
// This is the transaction proposal and response (from the peers).
const proposalResponses = [{
response: {
status: 200
}
}];
const proposal = { proposal: 'i do' };
const header = { header: 'gooooal' };
mockChain.sendTransactionProposal.resolves([ proposalResponses, proposal, header ]);
// This is the commit proposal and response (from the orderer).
const response = {
status: 'SUCCESS'
};
mockChain.sendTransaction.withArgs({ proposalResponses: proposalResponses, proposal: proposal, header: header }).resolves(response);
// This is the event hub response.
sandbox.stub(global, 'setTimeout').yields();
// mockEventHub.registerTxEvent.yields();
return connection.invokeChainCode(mockSecurityContext, 'myfunc', ['arg1', 'arg2'])
.catch(() => {
sinon.assert.calledWith(global.setTimeout, sinon.match.func, sinon.match.number);
sinon.assert.calledWith(global.setTimeout, sinon.match.func, connectOptions.invokeWaitTime * 1000);
});
});


it('should throw an error if the commit of the transaction times out', () => {
// This is the generated nonce.
sandbox.stub(utils, 'getNonce').returns('11111111-1111-1111-1111-111111111111');
Expand Down
3 changes: 2 additions & 1 deletion packages/composer-systests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"test": "exit 0",
"systest:embedded": "mocha -t 0 systest",
"systest:hlf": "mocha -t 0 systest",
"systest:hlfv1": "mocha -t 0 systest",
"systest:hlfv1-1": "mocha -t 0 systest/[a-p]*.js systest/setup.js",
"systest:hlfv1-2": "mocha -t 0 systest/[q-z]*.js systest/setup.js",
"systest:web": "karma start --single-run"
},
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions packages/composer-systests/scripts/run-system-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi

# Set default timeouts
export CONCERTO_PORT_WAIT_SECS=30
export CONCERTO_DEPLOY_WAIT_SECS=120
export CONCERTO_DEPLOY_WAIT_SECS=500

# Pull any required Docker images.
if [ "${SYSTEST}" = "hlf" -a "${SYSTEST_HLF}" = "hlf" ]; then
Expand All @@ -31,7 +31,7 @@ if [ "${SYSTEST}" = "hlf" -a "${SYSTEST_HLF}" = "hlf" ]; then
docker tag hyperledger/fabric-peer:x86_64-0.6.1-preview hyperledger/fabric-peer:latest
docker pull hyperledger/fabric-baseimage:x86_64-0.2.0
docker tag hyperledger/fabric-baseimage:x86_64-0.2.0 hyperledger/fabric-baseimage:latest
elif [ "${SYSTEST}" = "hlfv1" -a "${SYSTEST_HLF}" = "hlf" ]; then
elif [[ ${SYSTEST} == hlfv1* && "${SYSTEST_HLF}" = "hlf" ]]; then
DOCKER_FILE=${DIR}/systestv1/hlfv1_alpha-docker-compose.yml
docker pull hyperledger/fabric-peer:x86_64-1.0.0-alpha
docker pull hyperledger/fabric-ca:x86_64-1.0.0-alpha
Expand Down Expand Up @@ -71,7 +71,7 @@ rm -rf ${HOME}/.composer-connection-profiles/concerto-systests
rm -rf ${HOME}/.concerto-credentials/concerto-systests

# configure v1 to run the tests
if [ "${SYSTEST}" = "hlfv1" -a "${SYSTEST_HLF}" = "hlf" ]; then
if [[ ${SYSTEST} == hlfv1* && "${SYSTEST_HLF}" = "hlf" ]]; then
sleep 10
cd systestv1
node create-channel.js
Expand Down
10 changes: 6 additions & 4 deletions packages/composer-systests/systest/testutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class TestUtil {
if (!TestUtil.isHyperledgerFabric()) {
return Promise.resolve();
}
if (process.env.SYSTEST === 'hlfv1') {
// startsWith not available in browser test environment
if (process.env.SYSTEST.match('^hlfv1')) {
return Promise.resolve();
}
return TestUtil.waitForPort('localhost', 7050)
Expand Down Expand Up @@ -154,7 +155,7 @@ class TestUtil {
let keyValStore = path.resolve(homedir(), '.concerto-credentials', 'concerto-systests');
mkdirp.sync(keyValStore);

if (process.env.SYSTEST === 'hlfv1') {
if (process.env.SYSTEST.match('^hlfv1')) {
adminOptions = {
type: 'hlfv1',
orderers: [
Expand Down Expand Up @@ -199,7 +200,7 @@ class TestUtil {
.then(function () {
console.log('Called AdminConnection.createProfile()');
console.log('Calling AdminConnection.connect() ...');
let password = process.env.SYSTEST === 'hlfv1' ? 'adminpw' : 'Xurw3yU9zI0l';
let password = TestUtil.isHyperledgerFabric() && process.env.SYSTEST.match('^hlfv1') ? 'adminpw' : 'Xurw3yU9zI0l';
return adminConnection.connect('concerto-systests', 'admin', password);
})
.then(function () {
Expand Down Expand Up @@ -263,7 +264,8 @@ class TestUtil {
})
.then(() => {
enrollmentID = enrollmentID || 'admin';
enrollmentSecret = enrollmentSecret || 'Xurw3yU9zI0l';
let password = TestUtil.isHyperledgerFabric() && process.env.SYSTEST.match('^hlfv1') ? 'adminpw' : 'Xurw3yU9zI0l';
enrollmentSecret = enrollmentSecret || password;
console.log(`Calling Client.connect('concerto-systest', '${network}', '${enrollmentID}', '${enrollmentSecret}') ...`);
return thisClient.connect('concerto-systests', network, enrollmentID, enrollmentSecret);
})
Expand Down
3 changes: 2 additions & 1 deletion packages/composer-systests/systestv1/setup-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ let ORGS = hfc.getConfigSetting('test-network');
*/
function getSubmitter(username, password, client, userOrg) {
let caUrl = ORGS[userOrg].ca;
let mspid = ORGS[userOrg].mspid;

return client.getUserContext(username)
.then((user) => {
Expand All @@ -102,7 +103,7 @@ function getSubmitter(username, password, client, userOrg) {
console.log('Successfully enrolled user \'' + username + '\'');

member = new User(username, client);
return member.setEnrollment(enrollment.key, enrollment.certificate);
return member.setEnrollment(enrollment.key, enrollment.certificate, mspid);
}).then(() => {
return client.setUserContext(member);
}).then(() => {
Expand Down

0 comments on commit 9caf34c

Please sign in to comment.