Skip to content

Commit

Permalink
Fix a bug in caliper engine (#1669)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Kelsey <[email protected]>
Co-authored-by: Dave Kelsey <[email protected]>
  • Loading branch information
davidkel and Dave Kelsey authored Dec 5, 2024
1 parent f5e5b55 commit a1d4c32
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 9 deletions.
5 changes: 3 additions & 2 deletions packages/caliper-core/lib/manager/caliper-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CaliperEngine {
this.networkConfig = networkConfig;
this.workspace = ConfigUtils.get(ConfigUtils.keys.Workspace);
this.returnCode = -1;
this.roundOrchestrator = null;

this.adapterFactory = adapterFactory;
}
Expand Down Expand Up @@ -149,8 +150,8 @@ class CaliperEngine {
connector = connector ? connector : await this.adapterFactory(-1);
let workerArguments = await connector.prepareWorkerArguments(numberOfWorkers);

const roundOrchestrator = new RoundOrchestrator(this.benchmarkConfig, this.networkConfig, workerArguments);
await roundOrchestrator.run();
this.roundOrchestrator = new RoundOrchestrator(this.benchmarkConfig, this.networkConfig, workerArguments);
await this.roundOrchestrator.run();
}
} catch (err) {
// this means that we haven't handled/logged this failure yet
Expand Down
95 changes: 88 additions & 7 deletions packages/caliper-core/test/manager/caliper-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,37 @@

const sinon = require('sinon');
const chai = require('chai');
//const RoundOrchestrator = require('../../lib/manager/orchestrators/round-orchestrator');
const ConnectorBase = require('../../lib/common/core/connector-base');
const mockery = require('mockery');

//
// Simple RoundOrchestrator Stub
//
let roundOrchestratorStopCalled = false;
let roundOrchestratorRunCalled = false;
class StubRoundOrchestrator {

run() {roundOrchestratorRunCalled = true}
stop() {roundOrchestratorStopCalled = true}
}

mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true
});

mockery.registerMock('./orchestrators/round-orchestrator', StubRoundOrchestrator);

const CaliperEngine = require('../../lib/manager/caliper-engine')
const expect = chai.expect;

after(() => {
mockery.deregisterAll();
mockery.disable();
});

describe('CaliperEngine', function() {

describe('Initialization', function() {
Expand Down Expand Up @@ -131,13 +160,65 @@ describe('CaliperEngine', function() {
});
});

describe('Benchmark Stop Functionality', function() {
it('should stop the benchmark if the benchmark has been started', function() {
// TODO: Implement test
});

it('should do nothing if no benchmark run has been started', function() {
// TODO: Implement test
describe.only('When a Benchmark Stop is requested', function() {
let benchmarkConfig, networkConfig, engine;
let adaptorFactory = sinon.stub().returns(sinon.createStubInstance(ConnectorBase));
beforeEach(() =>{
benchmarkConfig = {
test: {
workers: {
number: 1,
},
rounds: [
{
label: 'function test',
contractId: 'xContract',
txDuration: 30,
rateControl: {
type: 'fixed-rate',
opts: {
tps: 10
}
},
workload: {
module: 'benchmarks/workloads/workload.js',
arguments: {
contractId: 'xContract',
contractVersion: '1.0.0'
}
}
}
]

},
};
networkConfig = {
caliper: {
command: {
start: 'echo "Starting network"',
end: 'echo "Stopping network"',
},
},
};

engine = new CaliperEngine(benchmarkConfig, networkConfig, adaptorFactory);
});

it('should stop the benchmark if the benchmark has been started', async function() {
roundOrchestratorRunCalled = false;
roundOrchestratorStopCalled = false;
await engine.run();
expect(roundOrchestratorRunCalled).to.be.true;
await engine.stop();
expect(roundOrchestratorStopCalled).to.be.true;
});

it('should do nothing if no benchmark run has been started', async function() {
roundOrchestratorRunCalled = false;
roundOrchestratorStopCalled = false;
expect(roundOrchestratorRunCalled).to.be.false;
await engine.stop();
expect(roundOrchestratorStopCalled).to.be.false;
});
});
});

0 comments on commit a1d4c32

Please sign in to comment.