diff --git a/packages/caliper-core/lib/worker/rate-control/compositeRate.js b/packages/caliper-core/lib/worker/rate-control/compositeRate.js index a1ce22dd4..2d38e1390 100644 --- a/packages/caliper-core/lib/worker/rate-control/compositeRate.js +++ b/packages/caliper-core/lib/worker/rate-control/compositeRate.js @@ -82,21 +82,20 @@ class CompositeRateController extends RateInterface{ this.controllers = []; this.activeControllerIndex = 0; - this.clientIdx = -1; + this.clientIdx = clientIdx + 1; + this.roundIndex = roundIdx; this.controllerSwitch = null; this.logControllerChange = (this.options.logChange && typeof(this.options.logChange) === 'boolean' && this.options.logChange) || false; - this.__prepareControllers(clientIdx, roundIdx); + this.__prepareControllers(); } /** * Internal method for preparing the controllers for further use. - * @param {number} clientIdx The 0-based index of the client who instantiates the controller. - * @param {number} roundIdx The 1-based index of the round the controller is instantiated in. * @private */ - __prepareControllers(clientIdx, roundIdx) { + __prepareControllers() { let weights = this.options.weights; let rateControllers = this.options.rateControllers; @@ -136,7 +135,7 @@ class CompositeRateController extends RateInterface{ continue; } - let info = new ControllerData(weights[i], rateControllers[i], new RateControl(rateControllers[i], clientIdx, roundIdx)); + let info = new ControllerData(weights[i], rateControllers[i], new RateControl(rateControllers[i], this.clientIdx, this.roundIndex)); this.controllers.push(info); } diff --git a/packages/caliper-core/lib/worker/rate-control/recordRate.js b/packages/caliper-core/lib/worker/rate-control/recordRate.js index 825790fa5..2b824bf50 100644 --- a/packages/caliper-core/lib/worker/rate-control/recordRate.js +++ b/packages/caliper-core/lib/worker/rate-control/recordRate.js @@ -47,6 +47,8 @@ class RecordRateController extends RateInterface{ */ constructor(opts, clientIdx, roundIdx) { super(opts); + this.roundIdx = roundIdx; + this.clientIdx = clientIdx + 1; this.records = []; if (typeof opts.pathTemplate === 'undefined') { @@ -137,9 +139,6 @@ class RecordRateController extends RateInterface{ * @async */ async init(msg) { - this.roundIdx = msg.roundIdx; - this.clientIdx = msg.clientIdx + 1; - // if we know the number of transactions beforehand, pre-allocate the array if (msg.numb) { this.records = new Array(msg.numb); diff --git a/packages/caliper-core/lib/worker/rate-control/replayRate.js b/packages/caliper-core/lib/worker/rate-control/replayRate.js index e6871a69d..ee309a990 100644 --- a/packages/caliper-core/lib/worker/rate-control/replayRate.js +++ b/packages/caliper-core/lib/worker/rate-control/replayRate.js @@ -42,9 +42,13 @@ class ReplayRateController extends RateInterface{ * Creates a new instance of the {ReplayRateController} class. * @constructor * @param {object} opts Options for the rate controller. + * @param {number} clientIdx The 0-based index of the client who instantiates the controller. + * @param {number} roundIdx The 1-based index of the round the controller is instantiated in. */ - constructor(opts) { + constructor(opts, clientIdx, roundIdx) { super(opts); + this.roundIdx = roundIdx; + this.clientIdx = clientIdx + 1; this.records = []; if (typeof opts.pathTemplate === 'undefined') { @@ -123,9 +127,6 @@ class ReplayRateController extends RateInterface{ * @async */ async init(msg) { - this.roundIdx = msg.roundIdx; - this.clientIdx = msg.clientIdx + 1; - // resolve template path placeholders this.pathTemplate = this.pathTemplate.replace(//gi, this.roundIdx.toString()); this.pathTemplate = this.pathTemplate.replace(//gi, this.clientIdx.toString());