Skip to content

Commit

Permalink
[FAB-6217] NodeSDK - timeout not being passed
Browse files Browse the repository at this point in the history
The timeout setting was not being passed internally.
Added test case to verify that the value was being
passed and used. Also found issue with queryByChaincode
getting all peers on channel when network config was
loaded that only had one peer defined for query.

Updated the package for `nano` version so that the latest would
not be pulled, 'nano' is missing a dependency and the build
will fail with a missing model.

Change-Id: I4365712fb277ca344398ef0a39dc9241d4ab2057
Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
  • Loading branch information
harrisob committed Sep 21, 2017
1 parent b1b61a7 commit 582b981
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
8 changes: 4 additions & 4 deletions fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ var Channel = class {
logger.error('sendChainCodeProposal error ' + errorMsg);
return Promise.reject(new Error(errorMsg));
}
var peers = this._getTargets(request.targets, Constants.ENDORSING_PEER_ROLE);
var peers = this._getTargets(request.targets, Constants.NetworkConfig.ENDORSING_PEER_ROLE);

// args is optional because some chaincode may not need any input parameters during initialization
if (!request.args) {
Expand Down Expand Up @@ -1243,9 +1243,9 @@ var Channel = class {
if(!request) {
throw new Error('Missing request object for this transaction proposal');
}
request.targets = this._getTargets(request.targets, Constants.ENDORSING_PEER_ROLE);
request.targets = this._getTargets(request.targets, Constants.NetworkConfig.ENDORSING_PEER_ROLE);

return Channel.sendTransactionProposal(request, this._name, this._clientContext);
return Channel.sendTransactionProposal(request, this._name, this._clientContext, timeout);
}

/*
Expand Down Expand Up @@ -1502,7 +1502,7 @@ var Channel = class {
throw new Error('Missing request object for this queryByChaincode call.');
}

var targets = this._getTargets(request.targets, Constants.CHAINCODE_QUERY_ROLE);
var targets = this._getTargets(request.targets, Constants.NetworkConfig.CHAINCODE_QUERY_ROLE);
var signer = this._clientContext._getSigningIdentity(useAdmin);
var txId = new TransactionID(signer, useAdmin);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"jsrsasign": "6.2.2",
"log4js": "^0.6.38",
"mock-couch": "git+https://github.com/jimthematrix/mock-couch.git",
"nano": "^6.2.0",
"nano": "6.4.0",
"require-dir": "^0.3.0",
"rewire": "^2.5.2",
"sinon": "^3.2.1",
Expand Down
55 changes: 47 additions & 8 deletions test/integration/network-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,42 @@ test('\n\n***** use the network configuration file *****\n\n', function(t) {
/*
* S T A R T U S I N G
*/
/*
* switch to organization org1
*/
client.loadFromConfig('test/fixtures/org1.yaml');
t.pass('Successfully loaded \'admin\' for org1');

return client.initCredentialStores();
}).then((nothing) => {
t.pass('Successfully created the key value store and crypto store based on the config and network');

return client.setUserContext({username:'admin', password:'adminpw'});
}).then((admin) => {
t.pass('Successfully enrolled user \'admin\' for org2');
t.pass('Successfully enrolled user \'admin\' for org1');

let tx_id = client.newTransactionID(); // get a non admin transaction ID
var request = {
chaincodeId : 'example',
fcn: 'move',
args: ['a', 'b','100'],
txId: tx_id
//targets - Letting default to all endorsing peers defined on the channel in the network configuration
};

return channel.sendTransactionProposal(request, 1); //logged in as org1 user
}).then((results) => {
var proposalResponses = results[0];
for(var i in proposalResponses) {
let proposal_response = proposalResponses[i];
if( proposal_response instanceof Error && proposal_response.toString().indexOf('REQUEST_TIMEOUT') > 0) {
t.pass('Successfully cause a timeout error by setting the timeout setting to 1');
} else {
t.fail('Failed to get the timeout error');
}
}

// try again ...this time use a longer timeout
let tx_id = client.newTransactionID(); // get a non admin transaction ID
query_tx_id = tx_id.getTransactionID();
var request = {
Expand All @@ -326,13 +358,17 @@ test('\n\n***** use the network configuration file *****\n\n', function(t) {
//targets - Letting default to all endorsing peers defined on the channel in the network configuration
};

return channel.sendTransactionProposal(request); //logged in as org2 user
return channel.sendTransactionProposal(request, 3000); //logged in as org1 user
}).then((results) => {
var proposalResponses = results[0];
var proposal = results[1];
var all_good = true;
// Will check to be sure that we see two responses as there are two peers defined on this
// channel that are endorsing peers
var endorsed_responses = 0;
for(var i in proposalResponses) {
let one_good = false;
endorsed_responses++;
let proposal_response = proposalResponses[i];
if( proposal_response.response && proposal_response.response.status === 200) {
t.pass('transaction proposal has response status of good');
Expand All @@ -342,7 +378,7 @@ test('\n\n***** use the network configuration file *****\n\n', function(t) {
}
all_good = all_good & one_good;
}

t.equals(endorsed_responses, 2, 'Checking that there are the correct number of endorsed responses');
if (!all_good) {
t.fail('Failed to send invoke Proposal or receive valid response. Response null or status is not 200. exiting...');
throw new Error('Failed to send invoke Proposal or receive valid response. Response null or status is not 200. exiting...');
Expand All @@ -357,7 +393,7 @@ test('\n\n***** use the network configuration file *****\n\n', function(t) {
promises.push(channel.sendTransaction(request));

// be sure to get an eventhub the current user is authorized to use
var eventhub = client.getEventHub('peer0.org2.example.com');
var eventhub = client.getEventHub('peer0.org1.example.com');
eventhub.connect();

let txPromise = new Promise((resolve, reject) => {
Expand Down Expand Up @@ -402,7 +438,7 @@ test('\n\n***** use the network configuration file *****\n\n', function(t) {
// when using a network config
return client.setUserContext({username:'admin'});
}).then((admin) => {
t.pass('Successfully loaded user \'admin\' from store for org2');
t.pass('Successfully loaded user \'admin\' from store for org1');

var request = {
chaincodeId : 'example',
Expand All @@ -412,8 +448,11 @@ test('\n\n***** use the network configuration file *****\n\n', function(t) {

return channel.queryByChaincode(request); //logged in as user on org1
}).then((response_payloads) => {
// should only be one response ...as only one peer is defined as CHAINCODE_QUERY_ROLE
var query_responses = 0;
if (response_payloads) {
for(let i = 0; i < response_payloads.length; i++) {
query_responses++;
t.equal(
response_payloads[i].toString('utf8'),
'300',
Expand All @@ -423,11 +462,11 @@ test('\n\n***** use the network configuration file *****\n\n', function(t) {
t.fail('response_payloads is null');
throw new Error('Failed to get response on query');
}

t.equals(query_responses,1,'Checking that only one response was seen');
var memoryUsage = process.memoryUsage();
logger.debug(' Memory usage :: %j',memoryUsage);

return client.queryChannels('peer0.org2.example.com');
return client.queryChannels('peer0.org1.example.com');
}).then((results) => {
logger.debug(' queryChannels ::%j',results);
let found = false;
Expand All @@ -443,7 +482,7 @@ test('\n\n***** use the network configuration file *****\n\n', function(t) {
t.fail('Failed to find our channel in the result list');
}

return client.queryInstalledChaincodes('peer0.org2.example.com', true); // use admin
return client.queryInstalledChaincodes('peer0.org1.example.com', true); // use admin
}).then((results) => {
logger.debug(' queryInstalledChaincodes ::%j',results);
let found = false;
Expand Down

0 comments on commit 582b981

Please sign in to comment.