Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: CaptainIRS <[email protected]>
  • Loading branch information
CaptainIRS committed Aug 22, 2022
1 parent eb0b309 commit 541f2ab
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
19 changes: 19 additions & 0 deletions packages/caliper-cli/lib/launch/lib/launchManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ class LaunchManager {
sutType, Constants.Factories.Connector, require);

const engine = new CaliperEngine(benchmarkConfig, networkConfig, connectorFactory);
process.on('SIGINT', async () => {
// support a force stop
if (!this.terminationAlreadyRequested) {
this.terminationAlreadyRequested = true;
logger.info('Request to terminate received, stopping workers');
try {
await engine.stop();
} catch(error) {
logger.error(`Failed to stop workers: ${error}`);
process.exit(1);
}
logger.info('Workers terminated');
process.exit(0);
} else {
logger.info('Termination already requested, terminating immediately');
process.exit(2);
}
});

const response = await engine.run();

if (response === 0) {
Expand Down
9 changes: 9 additions & 0 deletions packages/caliper-core/lib/manager/caliper-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ class CaliperEngine {

return this.returnCode;
}

/**
* Stops the benchmark run
*/
async stop() {
if (this.roundOrchestrator) {
await this.roundOrchestrator.stop();

Check warning on line 189 in packages/caliper-core/lib/manager/caliper-engine.js

View check run for this annotation

Codecov / codecov/patch

packages/caliper-core/lib/manager/caliper-engine.js#L189

Added line #L189 was not covered by tests
}
}
}

module.exports = CaliperEngine;
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,6 @@ class RoundOrchestrator {
logger.error(`Could not prepare worker connections: ${err.stack || err}`);
}

process.on('SIGINT', async () => {
logger.info('SIGINT received, stopping workers');
await this._cleanup();
process.exit(0);
});

let benchStartTime = Date.now();

for (const [index, roundConfig] of roundConfigs.entries()) {
Expand Down Expand Up @@ -238,7 +232,7 @@ class RoundOrchestrator {
logger.error(`Error while finalizing the report: ${err.stack || err}`);
}

await this._cleanup();
await this.stop();

Check warning on line 235 in packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js

View check run for this annotation

Codecov / codecov/patch

packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js#L235

Added line #L235 was not covered by tests

let benchEndTime = Date.now();
logger.info(`Benchmark finished in ${(benchEndTime - benchStartTime)/1000.0} seconds. Total rounds: ${success + failed}. Successful rounds: ${success}. Failed rounds: ${failed}.`);

Check warning on line 238 in packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js

View check run for this annotation

Codecov / codecov/patch

packages/caliper-core/lib/manager/orchestrators/round-orchestrator.js#L237-L238

Added lines #L237 - L238 were not covered by tests
Expand All @@ -247,7 +241,7 @@ class RoundOrchestrator {
/**
* Stops the benchmark.
*/
async _cleanup() {
async stop() {
// clean up, with "silent" failure handling
try {
await this.monitorOrchestrator.stopAllMonitors();
Expand Down

0 comments on commit 541f2ab

Please sign in to comment.