diff --git a/packages/caliper-burrow/lib/burrowClientFactory.js b/packages/caliper-burrow/lib/burrowClientFactory.js index 94b7a066da..0f8298aab2 100644 --- a/packages/caliper-burrow/lib/burrowClientFactory.js +++ b/packages/caliper-burrow/lib/burrowClientFactory.js @@ -22,28 +22,15 @@ const path = require('path'); */ class BurrowClientFactory { - /** - * Require paths to configuration data used when calling new on fabric.js - * @param {String} absNetworkFile absolute workerPath - * @param {Sting} workspace_root root location - */ - constructor(absNetworkFile, workspace_root){ - this.absNetworkFile = absNetworkFile; - this.workspaceRoot = workspace_root; - } - - /** * Spawn the worker and perform required init * @returns {Object} the child process */ async spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './burrowClientWorker.js'), process.argv.slice(1), { env: process.env}); + const child = childProcess.fork(path.join(__dirname, './burrowClientWorker.js'), process.argv.slice(2), { env: process.env}); const msg = { - type: 'init', - absNetworkFile: this.absNetworkFile, - networkRoot: this.workspaceRoot + type: 'init' }; child.send(msg); diff --git a/packages/caliper-burrow/lib/burrowClientWorker.js b/packages/caliper-burrow/lib/burrowClientWorker.js index c3c1b7a7b8..41bd8646fb 100644 --- a/packages/caliper-burrow/lib/burrowClientWorker.js +++ b/packages/caliper-burrow/lib/burrowClientWorker.js @@ -14,7 +14,8 @@ 'use strict'; -const { CaliperLocalClient, CaliperUtils } = require('@hyperledger/caliper-core'); +const { CaliperLocalClient, CaliperUtils, ConfigUtil } = require('@hyperledger/caliper-core'); +const logger = CaliperUtils.getLogger('burrow-client'); const BurrowClient = require('./burrow'); let caliperClient; @@ -24,31 +25,47 @@ let caliperClient; process.on('message', async (message) => { if (!message.hasOwnProperty('type')) { - process.send({ type: 'error', data: 'unknown message type' }); + let msg = 'Message type is missing'; + logger.error(msg, message); + process.send({type: 'error', data: msg}); return; } try { switch (message.type) { case 'init': { - const blockchain = new BurrowClient(message.absNetworkFile, message.networkRoot); + logger.info('Handling "init" message'); + logger.debug('Message content', message); + + const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace); + let networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig); + networkConfigPath = CaliperUtils.resolvePath(networkConfigPath); + + const blockchain = new BurrowClient(networkConfigPath, workspacePath); caliperClient = new CaliperLocalClient(blockchain); process.send({ type: 'ready', data: { pid: process.pid, complete: true } }); + logger.info('Handled "init" message'); break; } case 'test': { + logger.info('Handling "test" message'); + logger.debug('Message content', message); let result = await caliperClient.doTest(message); await CaliperUtils.sleep(200); process.send({ type: 'testResult', data: result }); + logger.info('Handled "test" message'); break; } default: { - process.send({ type: 'error', data: 'unknown message type [' + message.type + ']' }); + let msg = `Unknown message type "${message.type}"`; + logger.error(msg, message); + process.send({type: 'error', data: msg}); } } } catch (err) { - process.send({ type: 'error', data: err.toString() }); + logger.error(`Error while handling "${message.type}" message: ${err.stack || err}`); + process.send({type: 'error', data: err.toString()}); } }); diff --git a/packages/caliper-cli/lib/benchmark/lib/runBenchmark.js b/packages/caliper-cli/lib/benchmark/lib/runBenchmark.js index 3b4e29aa87..5ce3670532 100644 --- a/packages/caliper-cli/lib/benchmark/lib/runBenchmark.js +++ b/packages/caliper-cli/lib/benchmark/lib/runBenchmark.js @@ -72,7 +72,7 @@ class RunBenchmark { const {AdminClient, ClientFactory} = require(`@hyperledger/caliper-${blockchainType}`); const blockchainAdapter = new AdminClient(networkConfigPath, workspacePath); - const workerFactory = new ClientFactory(networkConfigPath, workspacePath); + const workerFactory = new ClientFactory(); const engine = new CaliperEngine(benchmarkConfig, networkConfig, blockchainAdapter, workerFactory); const response = await engine.run(); diff --git a/packages/caliper-composer/lib/composerClientFactory.js b/packages/caliper-composer/lib/composerClientFactory.js index f60803f6b7..001e4eb1a3 100644 --- a/packages/caliper-composer/lib/composerClientFactory.js +++ b/packages/caliper-composer/lib/composerClientFactory.js @@ -22,28 +22,15 @@ const path = require('path'); */ class ComposerClientFactory { - /** - * Require paths to configuration data used when calling new on fabric.js - * @param {String} absNetworkFile absolute workerPath - * @param {Sting} workspace_root root location - */ - constructor(absNetworkFile, workspace_root){ - this.absNetworkFile = absNetworkFile; - this.workspaceRoot = workspace_root; - } - - /** * Spawn the worker and perform required init * @returns {Object} the child process */ spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './composerClientWorker.js'), process.argv.slice(1), { env: process.env}); + const child = childProcess.fork(path.join(__dirname, './composerClientWorker.js'), process.argv.slice(2), { env: process.env}); const msg = { - type: 'init', - absNetworkFile: this.absNetworkFile, - networkRoot: this.workspaceRoot + type: 'init' }; child.send(msg); diff --git a/packages/caliper-composer/lib/composerClientWorker.js b/packages/caliper-composer/lib/composerClientWorker.js index 2638f9fd1a..0bb895b762 100644 --- a/packages/caliper-composer/lib/composerClientWorker.js +++ b/packages/caliper-composer/lib/composerClientWorker.js @@ -14,7 +14,8 @@ 'use strict'; -const {CaliperLocalClient, CaliperUtils} = require('@hyperledger/caliper-core'); +const {CaliperLocalClient, CaliperUtils, ConfigUtil} = require('@hyperledger/caliper-core'); +const logger = CaliperUtils.getLogger('composer-client'); const ComposerClient = require('./composer'); let caliperClient; @@ -24,31 +25,47 @@ let caliperClient; process.on('message', async (message) => { if (!message.hasOwnProperty('type')) { - process.send({type: 'error', data: 'unknown message type'}); + let msg = 'Message type is missing'; + logger.error(msg, message); + process.send({type: 'error', data: msg}); return; } try { switch (message.type) { case 'init': { - const blockchain = new ComposerClient(message.absNetworkFile, message.networkRoot); + logger.info('Handling "init" message'); + logger.debug('Message content', message); + + const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace); + let networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig); + networkConfigPath = CaliperUtils.resolvePath(networkConfigPath); + + const blockchain = new ComposerClient(networkConfigPath, workspacePath); caliperClient = new CaliperLocalClient(blockchain); process.send({type: 'ready', data: {pid: process.pid, complete: true}}); + logger.info('Handled "init" message'); break; } case 'test': { + logger.info('Handling "test" message'); + logger.debug('Message content', message); let result = await caliperClient.doTest(message); await CaliperUtils.sleep(200); process.send({type: 'testResult', data: result}); + logger.info('Handled "test" message'); break; } default: { - process.send({type: 'error', data: 'unknown message type [' + message.type + ']'}); + let msg = `Unknown message type "${message.type}"`; + logger.error(msg, message); + process.send({type: 'error', data: msg}); } } } catch (err) { + logger.error(`Error while handling "${message.type}" message: ${err.stack || err}`); process.send({type: 'error', data: err.toString()}); } }); diff --git a/packages/caliper-core/lib/common/utils/logging-util.js b/packages/caliper-core/lib/common/utils/logging-util.js index 3ede7d74aa..890ece83de 100644 --- a/packages/caliper-core/lib/common/utils/logging-util.js +++ b/packages/caliper-core/lib/common/utils/logging-util.js @@ -48,7 +48,7 @@ function _messageFormat() { output = output.replace(labelRegex, info.label || ''); output = output.replace(moduleRegex, info.module || ''); output = output.replace(messageRegex, info.message || ''); - return output.replace(metadataRegex, info.meta || ''); + return output.replace(metadataRegex, info.metadata || ''); }); } diff --git a/packages/caliper-core/lib/master/caliper-engine.js b/packages/caliper-core/lib/master/caliper-engine.js index c1a5803297..c6f519bac8 100644 --- a/packages/caliper-core/lib/master/caliper-engine.js +++ b/packages/caliper-core/lib/master/caliper-engine.js @@ -36,10 +36,11 @@ class CaliperEngine { constructor(benchmarkConfig, networkConfig, blockchainAdapter, workerFactory) { this.benchmarkConfig = benchmarkConfig; this.networkConfig = networkConfig; + this.workspace = ConfigUtils.get(ConfigUtils.keys.Workspace); + this.returnCode = -1; + this.blockchainAdapter = blockchainAdapter; this.workerFactory = workerFactory; - this.workspace = ConfigUtils.get(ConfigUtils.keys.workspace); - this.returnCode = -1; } /** diff --git a/packages/caliper-core/lib/master/client/client-orchestrator.js b/packages/caliper-core/lib/master/client/client-orchestrator.js index db2648d6ca..f7499cf9cb 100644 --- a/packages/caliper-core/lib/master/client/client-orchestrator.js +++ b/packages/caliper-core/lib/master/client/client-orchestrator.js @@ -40,6 +40,8 @@ class ClientOrchestrator { this.number = 1; } + logger.info(`Configured number of worker processes: ${this.number}`); + this.updates = {id:0, data:[]}; // contains txUpdated messages this.processes = {}; } diff --git a/packages/caliper-core/lib/master/test-runners/round-orchestrator.js b/packages/caliper-core/lib/master/test-runners/round-orchestrator.js index fc258a7ef2..fd3b84ce67 100644 --- a/packages/caliper-core/lib/master/test-runners/round-orchestrator.js +++ b/packages/caliper-core/lib/master/test-runners/round-orchestrator.js @@ -20,7 +20,6 @@ const MonitorOrchestrator = require('../monitor/monitor-orchestrator'); const Report = require('../report/report'); const TestObserver = require('../test-observers/test-observer'); const CaliperUtils = require('../../common/utils/caliper-utils'); -const ConfigUtils = require('../../common/config/config-util'); const logger = CaliperUtils.getLogger('round-orchestrator'); /** @@ -39,8 +38,6 @@ class RoundOrchestrator { this.networkConfig = networkConfig; this.benchmarkConfig = benchmarkConfig; - this.workspace = ConfigUtils.get(ConfigUtils.keys.Workspace); // TODO: remove this - this.clientOrchestrator = new ClientOrchestrator(this.benchmarkConfig, workerFactory, workerArguments); this.monitorOrchestrator = new MonitorOrchestrator(this.benchmarkConfig); this.report = new Report(this.monitorOrchestrator, this.benchmarkConfig, this.networkConfig); @@ -151,8 +148,6 @@ class RoundOrchestrator { trim: round.trim || 0, args: round.arguments, cb: round.callback, - config: 'TODO', // TODO: remove this - root: this.workspace, // TODO: remove this testRound: index, pushUrl: this.monitorOrchestrator.hasMonitor('prometheus') ? this.monitorOrchestrator.getMonitor('prometheus').getPushGatewayURL() : null }; diff --git a/packages/caliper-core/lib/worker/client/caliper-local-client.js b/packages/caliper-core/lib/worker/client/caliper-local-client.js index 29d80def50..50b8a501cc 100644 --- a/packages/caliper-core/lib/worker/client/caliper-local-client.js +++ b/packages/caliper-core/lib/worker/client/caliper-local-client.js @@ -307,7 +307,7 @@ class CaliperLocalClient { */ async doTest(test) { Logger.debug('doTest() with:', test); - let cb = require(CaliperUtils.resolvePath(test.cb, test.root)); + let cb = require(CaliperUtils.resolvePath(test.cb)); this.beforeTest(test); diff --git a/packages/caliper-ethereum/lib/ethereumClientFactory.js b/packages/caliper-ethereum/lib/ethereumClientFactory.js index 3aa4999299..ac7a5a8487 100644 --- a/packages/caliper-ethereum/lib/ethereumClientFactory.js +++ b/packages/caliper-ethereum/lib/ethereumClientFactory.js @@ -22,28 +22,15 @@ const path = require('path'); */ class EthereumClientFactory { - /** - * Require paths to configuration data used when calling new on fabric.js - * @param {String} absNetworkFile absolute workerPath - * @param {Sting} workspace_root root location - */ - constructor(absNetworkFile, workspace_root){ - this.absNetworkFile = absNetworkFile; - this.workspaceRoot = workspace_root; - } - - /** * Spawn the worker and perform required init * @returns {Object} the child process */ spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './ethereumClientWorker.js'), process.argv.slice(1), { env: process.env}); + const child = childProcess.fork(path.join(__dirname, './ethereumClientWorker.js'), process.argv.slice(2), { env: process.env}); const msg = { - type: 'init', - absNetworkFile: this.absNetworkFile, - networkRoot: this.workspaceRoot + type: 'init' }; child.send(msg); diff --git a/packages/caliper-ethereum/lib/ethereumClientWorker.js b/packages/caliper-ethereum/lib/ethereumClientWorker.js index d189ade147..e4d431dc97 100644 --- a/packages/caliper-ethereum/lib/ethereumClientWorker.js +++ b/packages/caliper-ethereum/lib/ethereumClientWorker.js @@ -14,7 +14,8 @@ 'use strict'; -const {CaliperLocalClient, CaliperUtils} = require('@hyperledger/caliper-core'); +const {CaliperLocalClient, CaliperUtils, ConfigUtil} = require('@hyperledger/caliper-core'); +const logger = CaliperUtils.getLogger('ethereum-client'); const EthereumClient = require('./ethereum'); let caliperClient; @@ -24,31 +25,47 @@ let caliperClient; process.on('message', async (message) => { if (!message.hasOwnProperty('type')) { - process.send({type: 'error', data: 'unknown message type'}); + let msg = 'Message type is missing'; + logger.error(msg, message); + process.send({type: 'error', data: msg}); return; } try { switch (message.type) { case 'init': { - const blockchain = new EthereumClient(message.absNetworkFile, message.networkRoot); + logger.info('Handling "init" message'); + logger.debug('Message content', message); + + const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace); + let networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig); + networkConfigPath = CaliperUtils.resolvePath(networkConfigPath); + + const blockchain = new EthereumClient(networkConfigPath, workspacePath); caliperClient = new CaliperLocalClient(blockchain); process.send({type: 'ready', data: {pid: process.pid, complete: true}}); + logger.info('Handled "init" message'); break; } case 'test': { + logger.info('Handling "test" message'); + logger.debug('Message content', message); let result = await caliperClient.doTest(message); await CaliperUtils.sleep(200); process.send({type: 'testResult', data: result}); + logger.info('Handled "test" message'); break; } default: { - process.send({type: 'error', data: 'unknown message type [' + message.type + ']'}); + let msg = `Unknown message type "${message.type}"`; + logger.error(msg, message); + process.send({type: 'error', data: msg}); } } } catch (err) { + logger.error(`Error while handling "${message.type}" message: ${err.stack || err}`); process.send({type: 'error', data: err.toString()}); } }); diff --git a/packages/caliper-fabric/lib/fabricClientFactory.js b/packages/caliper-fabric/lib/fabricClientFactory.js index a627d10bba..eb00aa4089 100644 --- a/packages/caliper-fabric/lib/fabricClientFactory.js +++ b/packages/caliper-fabric/lib/fabricClientFactory.js @@ -22,28 +22,15 @@ const path = require('path'); */ class FabricClientFactory { - /** - * Require paths to configuration data used when calling new on fabric.js - * @param {String} absNetworkFile absolute workerPath - * @param {Sting} workspace_root root location - */ - constructor(absNetworkFile, workspace_root){ - this.absNetworkFile = absNetworkFile; - this.workspaceRoot = workspace_root; - } - - /** * Spawn the worker and perform required init * @returns {Object} the child process */ spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './fabricClientWorker.js'), process.argv.slice(1), { env: process.env}); + const child = childProcess.fork(path.join(__dirname, './fabricClientWorker.js'), process.argv.slice(2), { env: process.env}); const msg = { - type: 'init', - absNetworkFile: this.absNetworkFile, - networkRoot: this.workspaceRoot + type: 'init' }; child.send(msg); diff --git a/packages/caliper-fabric/lib/fabricClientWorker.js b/packages/caliper-fabric/lib/fabricClientWorker.js index 40be5f4b6b..7d12092796 100644 --- a/packages/caliper-fabric/lib/fabricClientWorker.js +++ b/packages/caliper-fabric/lib/fabricClientWorker.js @@ -14,10 +14,10 @@ 'use strict'; -const {CaliperLocalClient, CaliperUtils} = require('@hyperledger/caliper-core'); +const {CaliperLocalClient, CaliperUtils, ConfigUtil } = require('@hyperledger/caliper-core'); +const logger = CaliperUtils.getLogger('fabric-client'); const FabricClient = require('./fabric'); -const logger = CaliperUtils.getLogger('fabric/fabricClientWorker'); let caliperClient; /** * Message handler @@ -25,14 +25,23 @@ let caliperClient; process.on('message', async (message) => { if (!message.hasOwnProperty('type')) { - process.send({type: 'error', data: 'unknown message type'}); + let msg = 'Message type is missing'; + logger.error(msg, message); + process.send({type: 'error', data: msg}); return; } try { switch (message.type) { case 'init': { - const blockchain = new FabricClient(message.absNetworkFile, message.networkRoot); + logger.info('Handling "init" message'); + logger.debug('Message content', message); + + const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace); + let networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig); + networkConfigPath = CaliperUtils.resolvePath(networkConfigPath); + + const blockchain = new FabricClient(networkConfigPath, workspacePath); // reload the profiles silently await blockchain._initializeRegistrars(false); await blockchain._initializeAdmins(false); @@ -40,23 +49,28 @@ process.on('message', async (message) => { caliperClient = new CaliperLocalClient(blockchain); process.send({type: 'ready', data: {pid: process.pid, complete: true}}); - - logger.info('Client ready'); + logger.info('Handled "init" message'); break; } case 'test': { + logger.info('Handling "test" message'); + logger.debug('Message content', message); let result = await caliperClient.doTest(message); await CaliperUtils.sleep(200); process.send({type: 'testResult', data: result}); + logger.info('Handled "test" message'); break; } default: { - process.send({type: 'error', data: 'unknown message type [' + message.type + ']'}); + let msg = `Unknown message type "${message.type}"`; + logger.error(msg, message); + process.send({type: 'error', data: msg}); } } } catch (err) { + logger.error(`Error while handling "${message.type}" message: ${err.stack || err}`); process.send({type: 'error', data: err.toString()}); } }); diff --git a/packages/caliper-fisco-bcos/lib/fiscoBcosClientFactory.js b/packages/caliper-fisco-bcos/lib/fiscoBcosClientFactory.js index 1f8b86d34c..f50d72a2da 100644 --- a/packages/caliper-fisco-bcos/lib/fiscoBcosClientFactory.js +++ b/packages/caliper-fisco-bcos/lib/fiscoBcosClientFactory.js @@ -21,27 +21,16 @@ const path = require('path'); * Class used to spawn FISCO BCOS client workers */ class FiscoBcosClientFactory { - /** - * Require paths to configuration data used when calling new on fiscoBcos.js - * @param {String} absNetworkFile absolute workerPath - * @param {Sting} workspace_root root location - */ - constructor(absNetworkFile, workspace_root) { - this.absNetworkFile = absNetworkFile; - this.workspaceRoot = workspace_root; - } /** * Spawn the worker and perform required init * @returns {Object} the child process */ spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './fiscoBcosClientWorker.js'), process.argv.slice(1), { env: process.env }); + const child = childProcess.fork(path.join(__dirname, './fiscoBcosClientWorker.js'), process.argv.slice(2), { env: process.env }); const msg = { - type: 'init', - absNetworkFile: this.absNetworkFile, - networkRoot: this.workspaceRoot + type: 'init' }; child.send(msg); diff --git a/packages/caliper-fisco-bcos/lib/fiscoBcosClientWorker.js b/packages/caliper-fisco-bcos/lib/fiscoBcosClientWorker.js index bf0da9c608..38526aef4b 100644 --- a/packages/caliper-fisco-bcos/lib/fiscoBcosClientWorker.js +++ b/packages/caliper-fisco-bcos/lib/fiscoBcosClientWorker.js @@ -16,8 +16,10 @@ const { CaliperLocalClient, - CaliperUtils + CaliperUtils, + ConfigUtil } = require('@hyperledger/caliper-core'); +const logger = CaliperUtils.getLogger('fisco-bcos-client'); const fiscoBcosClient = require('./fiscoBcos'); let caliperClient; @@ -27,17 +29,23 @@ let caliperClient; */ process.on('message', async (message) => { if (!message.hasOwnProperty('type')) { - process.send({ - type: 'error', - data: 'unknown message type' - }); + let msg = 'Message type is missing'; + logger.error(msg, message); + process.send({type: 'error', data: msg}); return; } try { switch (message.type) { case 'init': { - const blockchain = new fiscoBcosClient(message.absNetworkFile, message.networkRoot); + logger.info('Handling "init" message'); + logger.debug('Message content', message); + + const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace); + let networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig); + networkConfigPath = CaliperUtils.resolvePath(networkConfigPath); + + const blockchain = new fiscoBcosClient(networkConfigPath, workspacePath); caliperClient = new CaliperLocalClient(blockchain); process.send({ type: 'ready', @@ -46,9 +54,12 @@ process.on('message', async (message) => { complete: true } }); + logger.info('Handled "init" message'); break; } case 'test': { + logger.info('Handling "test" message'); + logger.debug('Message content', message); let result = await caliperClient.doTest(message); await CaliperUtils.sleep(200); @@ -56,19 +67,17 @@ process.on('message', async (message) => { type: 'testResult', data: result }); + logger.info('Handled "test" message'); break; } default: { - process.send({ - type: 'error', - data: `unknown message type [${message.type}]` - }); + let msg = `Unknown message type "${message.type}"`; + logger.error(msg, message); + process.send({type: 'error', data: msg}); } } - } catch (error) { - process.send({ - type: 'error', - data: error.toString() - }); + } catch (err) { + logger.error(`Error while handling "${message.type}" message: ${err.stack || err}`); + process.send({type: 'error', data: err.toString()}); } }); diff --git a/packages/caliper-iroha/lib/irohaClientFactory.js b/packages/caliper-iroha/lib/irohaClientFactory.js index 9ffac15c43..516d9fd3dc 100644 --- a/packages/caliper-iroha/lib/irohaClientFactory.js +++ b/packages/caliper-iroha/lib/irohaClientFactory.js @@ -22,28 +22,15 @@ const path = require('path'); */ class IrohaClientFactory { - /** - * Require paths to configuration data used when calling new on fabric.js - * @param {String} absNetworkFile absolute workerPath - * @param {Sting} workspace_root root location - */ - constructor(absNetworkFile, workspace_root){ - this.absNetworkFile = absNetworkFile; - this.workspaceRoot = workspace_root; - } - - /** * Spawn the worker and perform required init * @returns {Object} the child process */ spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './irohaClientWorker.js'), process.argv.slice(1), { env: process.env}); + const child = childProcess.fork(path.join(__dirname, './irohaClientWorker.js'), process.argv.slice(2), { env: process.env}); const msg = { - type: 'init', - absNetworkFile: this.absNetworkFile, - networkRoot: this.workspaceRoot + type: 'init' }; child.send(msg); diff --git a/packages/caliper-iroha/lib/irohaClientWorker.js b/packages/caliper-iroha/lib/irohaClientWorker.js index 2b32bd2c30..1f53419d7c 100644 --- a/packages/caliper-iroha/lib/irohaClientWorker.js +++ b/packages/caliper-iroha/lib/irohaClientWorker.js @@ -14,7 +14,8 @@ 'use strict'; -const {CaliperLocalClient, CaliperUtils} = require('@hyperledger/caliper-core'); +const {CaliperLocalClient, CaliperUtils, ConfigUtil} = require('@hyperledger/caliper-core'); +const logger = CaliperUtils.getLogger('iroha-client'); const IrohaClient = require('./iroha'); let caliperClient; @@ -24,31 +25,47 @@ let caliperClient; process.on('message', async (message) => { if (!message.hasOwnProperty('type')) { - process.send({type: 'error', data: 'unknown message type'}); + let msg = 'Message type is missing'; + logger.error(msg, message); + process.send({type: 'error', data: msg}); return; } try { switch (message.type) { case 'init': { - const blockchain = new IrohaClient(message.absNetworkFile, message.networkRoot); + logger.info('Handling "init" message'); + logger.debug('Message content', message); + + const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace); + let networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig); + networkConfigPath = CaliperUtils.resolvePath(networkConfigPath); + + const blockchain = new IrohaClient(networkConfigPath, workspacePath); caliperClient = new CaliperLocalClient(blockchain); process.send({type: 'ready', data: {pid: process.pid, complete: true}}); + logger.info('Handled "init" message'); break; } case 'test': { + logger.info('Handling "test" message'); + logger.debug('Message content', message); let result = await caliperClient.doTest(message); await CaliperUtils.sleep(200); process.send({type: 'testResult', data: result}); + logger.info('Handled "test" message'); break; } default: { - process.send({type: 'error', data: 'unknown message type [' + message.type + ']'}); + let msg = `Unknown message type "${message.type}"`; + logger.error(msg, message); + process.send({type: 'error', data: msg}); } } } catch (err) { + logger.error(`Error while handling "${message.type}" message: ${err.stack || err}`); process.send({type: 'error', data: err.toString()}); } }); diff --git a/packages/caliper-sawtooth/lib/sawtoothClientFactory.js b/packages/caliper-sawtooth/lib/sawtoothClientFactory.js index 333c239b55..00c8d7db13 100644 --- a/packages/caliper-sawtooth/lib/sawtoothClientFactory.js +++ b/packages/caliper-sawtooth/lib/sawtoothClientFactory.js @@ -22,28 +22,15 @@ const path = require('path'); */ class SawtoothClientFactory { - /** - * Require paths to configuration data used when calling new on fabric.js - * @param {String} absNetworkFile absolute workerPath - * @param {Sting} workspace_root root location - */ - constructor(absNetworkFile, workspace_root){ - this.absNetworkFile = absNetworkFile; - this.workspaceRoot = workspace_root; - } - - /** * Spawn the worker and perform required init * @returns {Object} the child process */ spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './sawtoothClientWorker.js'), process.argv.slice(1), { env: process.env}); + const child = childProcess.fork(path.join(__dirname, './sawtoothClientWorker.js'), process.argv.slice(2), { env: process.env}); const msg = { - type: 'init', - absNetworkFile: this.absNetworkFile, - networkRoot: this.workspaceRoot + type: 'init' }; child.send(msg); diff --git a/packages/caliper-sawtooth/lib/sawtoothClientWorker.js b/packages/caliper-sawtooth/lib/sawtoothClientWorker.js index b1f94e3342..022cb5bc3b 100644 --- a/packages/caliper-sawtooth/lib/sawtoothClientWorker.js +++ b/packages/caliper-sawtooth/lib/sawtoothClientWorker.js @@ -14,7 +14,8 @@ 'use strict'; -const {CaliperLocalClient, CaliperUtils} = require('@hyperledger/caliper-core'); +const {CaliperLocalClient, CaliperUtils, ConfigUtil} = require('@hyperledger/caliper-core'); +const logger = CaliperUtils.getLogger('sawtooth-client'); const SawtoothClient = require('./sawtooth'); let caliperClient; @@ -24,31 +25,47 @@ let caliperClient; process.on('message', async (message) => { if (!message.hasOwnProperty('type')) { - process.send({type: 'error', data: 'unknown message type'}); + let msg = 'Message type is missing'; + logger.error(msg, message); + process.send({type: 'error', data: msg}); return; } try { switch (message.type) { case 'init': { - const blockchain = new SawtoothClient(message.absNetworkFile, message.networkRoot); + logger.info('Handling "init" message'); + logger.debug('Message content', message); + + const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace); + let networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig); + networkConfigPath = CaliperUtils.resolvePath(networkConfigPath); + + const blockchain = new SawtoothClient(networkConfigPath, workspacePath); caliperClient = new CaliperLocalClient(blockchain); process.send({type: 'ready', data: {pid: process.pid, complete: true}}); + logger.info('Handled "init" message'); break; } case 'test': { + logger.info('Handling "test" message'); + logger.debug('Message content', message); let result = await caliperClient.doTest(message); await CaliperUtils.sleep(200); process.send({type: 'testResult', data: result}); + logger.info('Handled "test" message'); break; } default: { - process.send({type: 'error', data: 'unknown message type [' + message.type + ']'}); + let msg = `Unknown message type "${message.type}"`; + logger.error(msg, message); + process.send({type: 'error', data: msg}); } } } catch (err) { + logger.error(`Error while handling "${message.type}" message: ${err.stack || err}`); process.send({type: 'error', data: err.toString()}); } }); diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh new file mode 100755 index 0000000000..e97f474675 --- /dev/null +++ b/scripts/run-tests.sh @@ -0,0 +1,35 @@ +#!/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 + +# Run linting, license check and unit tests +npm test + +# Call CLI directly +# The CWD will be in one of the caliper-tests-integration/*_tests directories +export CALL_METHOD="node ../../caliper-cli/caliper.js" + +IFS=' ' read -r -a array <<< "${TESTS}" + +cd ./packages/caliper-tests-integration/ + +for element in "${array[@]}" +do + export BENCHMARK="${element}" + npm run run_tests +done