Skip to content

Commit

Permalink
FABN-1336 NodeSDK typescript test fails
Browse files Browse the repository at this point in the history
Default for asLocalhost is now false and the
typesript tests needed to be adjusted. The overall
gulp tests were missing the integration testing due to a
change in checking for HSM. Added various debug to help in
the debug that will be left for future debugging of field issues.

Signed-off-by: Bret Harrison <[email protected]>
Change-Id: Idc697e5f1e37908ba876efee4fc395c49630e262
  • Loading branch information
harrisob committed Aug 5, 2019
1 parent 4e61f49 commit 53f51c2
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 24 deletions.
9 changes: 3 additions & 6 deletions build/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ gulp.task('compile', shell.task([
// - Cannot use gulp-istabul because it throws "unexpected identifier" for async/await functions

// Main test to run all tests
gulp.task('test', shell.task('npx nyc gulp run-test'));
gulp.task('test', shell.task('npx nyc gulp run-test-all'));

// Test to run all unit tests
gulp.task('test-headless', shell.task('npx gulp run-test-headless'));
Expand Down Expand Up @@ -170,7 +170,7 @@ gulp.task('mocha-fabric-client',
gulp.task('mocha-fabric-network',
() => {
return gulp.src(['./fabric-network/test/**/*.js'], {read: false})
.pipe(mocha({reporter: 'list', exit: true}));
.pipe(mocha({reporter: 'list', exit: true, timeout: 10000}));
}
);

Expand Down Expand Up @@ -287,7 +287,7 @@ gulp.task('run-tape-e2e', ['docker-ready'],
'test/integration/nodechaincode/e2e.js',
'test/integration/e2e.js',
'test/integration/network-e2e/e2e.js',
// 'test/integration/network-e2e/e2e-hsm.js',
'test/integration/network-e2e/e2e-hsm.js',
'test/integration/signTransactionOffline.js',
'test/integration/query.js',
'test/integration/client.js',
Expand Down Expand Up @@ -332,9 +332,6 @@ function shouldRunTests(tests) {
tests.push('!test/unit/pkcs11.js');
tests.push('!test/integration/network-e2e/e2e-hsm.js');
// check to see if they want to test PKCS11
} else if (typeof process.env.PKCS11_TESTS === 'string' && process.env.PKCS11_TESTS.toLowerCase() === 'true') {
tests.push('!test/integration/network-e2e/e2e.js');
// check to see if they do not want to test PKCS11
} else if (typeof process.env.PKCS11_TESTS === 'string' && process.env.PKCS11_TESTS.toLowerCase() === 'false') {
tests.push('!test/unit/pkcs11.js');
tests.push('!test/integration/network-e2e/e2e-hsm.js');
Expand Down
16 changes: 13 additions & 3 deletions fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ function logAndThrow(methodName, errorMessage) {
throw new Error(errorMessage);
}

let channel_count = 1;

/**
* Channels provide data isolation for a set of participating organizations.
* <br><br>
Expand Down Expand Up @@ -116,7 +118,8 @@ const Channel = class {
this._commit_handler = null;
this._prover_handler = null;

logger.debug('Constructed Channel instance: name - %s, network mode: %s', this._name, !this._devMode);
this._number = channel_count++;
logger.debug('Constructed Channel instance:%s name - %s, network mode: %s', this._number, this._name, !this._devMode);
}

/**
Expand Down Expand Up @@ -179,14 +182,16 @@ const Channel = class {
* @return {Promise} A Promise that will resolve when the action is complete
*/
async initialize(request) {
const method = 'initialize';
logger.debug('%s - start', method);
const method = 'initialize' + this._number;
logger.debug('%s - start channel:%s', method, this._name);

let endorsement_handler_path = null;
let commit_handler_path = null;
let prover_handler_path = null;

if (request) {
logger.debug('%s - request.asLocalhost:%s', method, request.asLocalhost);
logger.debug('%s - ConfigSetting-discovery-as-localhost:%s', method, sdk_utils.getConfigSetting('discovery-as-localhost'));
if (request.configUpdate) {
logger.debug('%s - have a configupdate', method);
this.loadConfigUpdate(request.configUpdate);
Expand Down Expand Up @@ -1489,7 +1494,10 @@ const Channel = class {

// endpoints may be running in containers on the local system
if (this._as_localhost) {
logger.debug('%s - mapping to localhost %s', method, t_hostname);
t_hostname = 'localhost';
} else {
logger.debug('%s - not mapping to localhost %s', method, t_hostname);
}

// If we connect to the discovery peer over TLS, any peers returned by
Expand Down Expand Up @@ -2859,7 +2867,9 @@ const Channel = class {
const method = 'sendTransactionProposal';
logger.debug('%s - start', method);


const errorMsg = client_utils.checkProposalRequest(request, true);

if (errorMsg) {
logAndThrow(method, errorMsg);
}
Expand Down
2 changes: 1 addition & 1 deletion fabric-client/lib/Remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Remote {
client.waitForReady(timeout, (err) => {
if (err) {
if (err.message) {
err.message = err.message + ' URL:' + self.getUrl();
err.message = err.message + ' URL:' + self.getUrl() + ' timeout:' + this._grpc_wait_for_ready_timeout;
}
err.connectFailed = true;
logger.error(err);
Expand Down
52 changes: 38 additions & 14 deletions fabric-client/lib/impl/DiscoveryEndorsementHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class DiscoveryEndorsementHandler extends EndorsementHandler {

async _endorse(endorsement_plan, request, proposal, timeout) {
const method = '_endorse';
logger.debug('%s - start', method);

// see if we have an endorsement plan for the requested chaincodes/collection call
if (endorsement_plan) {
Expand All @@ -136,12 +137,12 @@ class DiscoveryEndorsementHandler extends EndorsementHandler {
results.failed_endorsements = [];
results.success = false;

const required = this._create_map(request.required, 'endpoint');
const preferred = this._create_map(request.preferred, 'endpoint');
const ignored = this._create_map(request.ignored, 'endpoint');
const required_orgs = this._create_map(request.requiredOrgs, 'mspid');
const preferred_orgs = this._create_map(request.preferredOrgs, 'mspid');
const ignored_orgs = this._create_map(request.ignoredOrgs, 'mspid');
const required = this._create_map(request.required, 'required');
const preferred = this._create_map(request.preferred, 'preferred');
const ignored = this._create_map(request.ignored, 'ignored');
const required_orgs = this._create_map(request.requiredOrgs, 'requiredOrgs');
const preferred_orgs = this._create_map(request.preferredOrgs, 'preferredOrgs');
const ignored_orgs = this._create_map(request.ignoredOrgs, 'ignoredOrgs');
let preferred_height_gap = null;
try {
preferred_height_gap = Long.fromValue(request.preferredHeightGap);
Expand Down Expand Up @@ -182,7 +183,13 @@ class DiscoveryEndorsementHandler extends EndorsementHandler {

if (!results.success) {
const error = new Error('Endorsement has failed');
logger.error('%s - endorsement failed::%s', method, error.stack);
error.endorsements = results.failed_endorsements;
for (const endorsement of results.endorsements) {
if (endorsement instanceof Error) {
logger.error('%s - %s', method, endorsement.stack);
}
}
throw error;
}

Expand Down Expand Up @@ -345,30 +352,39 @@ class DiscoveryEndorsementHandler extends EndorsementHandler {

for (const group_name in endorsement_plan.groups) {
const group = endorsement_plan.groups[group_name];
logger.debug('%s starting - group: %s - size: %s', method, group_name, group.peers.length);
// remove ignored and non-required
const clean_list = this._removePeers(ignored, ignored_orgs, required, required_orgs, group.peers);
logger.debug('%s removed - group: %s - size: %s', method, group_name, clean_list.length);

// get the highest ledger height if needed
let highest = null;
if (preferred_height_gap) {
highest = this._findHighest(clean_list);
}
// sort based on ledger height or randomly
const sorted_list = this._sortPeerList(sort, clean_list);
logger.debug('%s sorted - group: %s - size: %s', method, group_name, sorted_list.length);
// pop the priority peers off the sorted list
const split_lists = this._splitList(preferred, preferred_orgs, highest, preferred_height_gap, sorted_list);
// put the priorities on top
const reordered_list = split_lists.priority.concat(split_lists.non_priority);
logger.debug('%s reordered - group: %s - size: %s', method, group_name, reordered_list.length);

// set the rebuilt peer list into the group
group.peers = reordered_list;
}

logger.debug('%s - updated endorsement_plan:%j', method, endorsement_plan);
}

_create_map(array) {
_create_map(items, type) {
const method = '_create_map';
logger.debug('%s - start for %s', method, type);
const map = new Map();
if (array && Array.isArray(array)) {
array.forEach((item) => {
if (items && Array.isArray(items)) {
items.forEach((item) => {
logger.debug('%s - adding %s', method, item);
map.set(item, item);
});
}
Expand All @@ -381,35 +397,42 @@ class DiscoveryEndorsementHandler extends EndorsementHandler {
*/
_removePeers(ignored_peers, ignored_orgs, required_peers, required_orgs, peers) {
const method = '_removePeers';
logger.debug('%s - start', method);
logger.debug('%s - start size:%s', method, peers.length);
const keep_list = [];
for (const peer of peers) {
let found = ignored_peers.has(peer.name);
if (!found) {
found = ignored_orgs.has(peer.mspid);
if (!found) {
logger.debug('%s - not found in ignored list - peer:%s', method, peer.name);
// if the user has requested required peers/orgs
// then all peers that stay on the list must be
// one of those peers or in one of those orgs
if (required_peers.size || required_orgs.size) {
if (required_peers.size > 0 || required_orgs.size > 0) {
found = required_peers.has(peer.name);
if (!found) {
logger.debug('%s - not found in required peers - peer:%s', method, peer.name);
found = required_orgs.has(peer.mspid);
}
// if we did not find it on a either list then
// this peer will not be added to the keep list
if (!found) {
logger.debug('%s - removing peer:%s', method, peer.name);
continue; // do not add this peer to the keep list
}
}

// looks like this peer is not on the ignored list and
// is on the required list (if being used);
logger.debug('%s - keeping peer:%s', method, peer.name);
keep_list.push(peer);
}
} else {
logger.debug('%s - found in ignored list - peer:%s', method, peer.name);
}
}

logger.debug('%s - end size:%s', method, keep_list.length);
return keep_list;
}

Expand All @@ -429,8 +452,8 @@ class DiscoveryEndorsementHandler extends EndorsementHandler {
}

_sortPeerList(sort, peers) {
const method = '_sortList';
logger.debug('%s - start - %s', method, sort);
const method = '_sortPeerList';
logger.debug('%s - start - sort:%s - size:%s', method, sort, peers.length);
let sorted = null;

if (!sort || sort === BLOCK_HEIGHT || sort === DEFAULT) {
Expand Down Expand Up @@ -474,7 +497,7 @@ class DiscoveryEndorsementHandler extends EndorsementHandler {

_splitList(preferred_peers, preferred_orgs, preferred_height_gap, highest, sorted_list) {
const method = '_splitList';
logger.debug('%s - start', method);
logger.debug('%s - start size:%s', method, sorted_list.length);
const list = {};
list.priority = [];
list.non_priority = [];
Expand Down Expand Up @@ -508,6 +531,7 @@ class DiscoveryEndorsementHandler extends EndorsementHandler {
}
}

logger.debug('%s - end - priority:%s - non_priority:%s', method, list.priority.length, list.non_priority.length);
return list;
}

Expand Down
12 changes: 12 additions & 0 deletions test/typescript/integration/network-e2e/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
try {
const contract = await createContract(t, gateway, {
clientTlsIdentity: 'tlsId',
discovery: {
asLocalhost: true,
enabled: true,
},
identity: '[email protected]',
wallet: inMemoryWallet,
});
Expand Down Expand Up @@ -424,6 +428,10 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
try {
const contract = await createContract(t, gateway, {
clientTlsIdentity: 'tlsId',
discovery: {
asLocalhost: true,
enabled: true,
},
eventHandlerOptions: {
strategy: DefaultEventHandlerStrategies.NETWORK_SCOPE_ALLFORTX,
},
Expand Down Expand Up @@ -552,6 +560,10 @@ test('\n\n***** Network End-to-end flow: invoke transaction to move money using
try {
const contract = await createContract(t, gateway, {
clientTlsIdentity: 'tlsId',
discovery: {
asLocalhost: true,
enabled: true,
},
eventHandlerOptions: {
strategy: DefaultEventHandlerStrategies.NETWORK_SCOPE_ANYFORTX,
},
Expand Down

0 comments on commit 53f51c2

Please sign in to comment.