Skip to content

Commit

Permalink
[FAB-11059] unit test for peer
Browse files Browse the repository at this point in the history
- add Peer unit test with 100% code coverage
- edit Peer.js to remove linting errors
- remove tape unit test for Peer

Change-Id: I4af0b13fa5eeffadc402ba39e3b5d77df3512399
Signed-off-by: nkl199@yahoo.co.uk <nkl199@yahoo.co.uk>
  • Loading branch information
nklincoln committed Aug 24, 2018
1 parent 5ef917f commit bb06fbc
Show file tree
Hide file tree
Showing 3 changed files with 500 additions and 250 deletions.
34 changes: 21 additions & 13 deletions fabric-client/lib/Peer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
/*
Copyright 2016, 2018 IBM All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
* 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';

Expand All @@ -25,7 +32,7 @@ const logger = utils.getLogger('Peer.js');
* @class
* @extends Remote
*/
var Peer = class extends Remote {
const Peer = class extends Remote {

/**
* Construct a Peer object with the given url and opts. A peer object
Expand Down Expand Up @@ -88,13 +95,14 @@ var Peer = class extends Remote {
}

return this.waitForReady(this._endorserClient).then(() => {
return new Promise(function(resolve, reject) {
const send_timeout = setTimeout(function(){
return new Promise((resolve, reject) => {
const send_timeout = setTimeout(() => {
clearTimeout(send_timeout);
logger.error('%s - timed out after:%s', method, rto);
return reject(new Error('REQUEST_TIMEOUT'));
}, rto);

self._endorserClient.processProposal(proposal, function(err, proposalResponse) {
self._endorserClient.processProposal(proposal, (err, proposalResponse) => {
clearTimeout(send_timeout);
if (err) {
logger.debug('%s - Received proposal response from: %s status: %s', method, self._url, err);
Expand All @@ -106,7 +114,7 @@ var Peer = class extends Remote {
}
} else {
if (proposalResponse) {
logger.debug('%s - Received proposal response from peer "%s": status - %s', method, self._url, proposalResponse.response.status);
logger.debug('%s - Received proposal response from peer "%s": status - %s', method, self._url, (proposalResponse.response && proposalResponse.response.status) ? proposalResponse.response.status : 'undefined');
// 400 is the error threshold level, anything below that the endorser will endorse it.
if (proposalResponse.response && proposalResponse.response.status < 400) {
resolve(proposalResponse);
Expand Down Expand Up @@ -150,13 +158,13 @@ var Peer = class extends Remote {
}

return this.waitForReady(this._discoveryClient).then(() => {
return new Promise(function(resolve, reject) {
const send_timeout = setTimeout(function(){
return new Promise((resolve, reject) => {
const send_timeout = setTimeout(() =>{
logger.error('%s - timed out after:%s', method, rto);
return reject(new Error('REQUEST_TIMEOUT'));
}, rto);

self._discoveryClient.discover(request, function(err, response) {
self._discoveryClient.discover(request, (err, response) => {
clearTimeout(send_timeout);
if (err) {
logger.debug('%s - Received discovery response from: %s status: %s', method, self._url, err);
Expand Down
Loading

0 comments on commit bb06fbc

Please sign in to comment.