Skip to content

Commit

Permalink
Update compositeRate.js
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinav Pandey <[email protected]>

Update compositeRate.js

Signed-off-by: Abhinav Pandey <[email protected]>

Revert unnecessary logs

Signed-off-by: Abhinav Pandey <[email protected]>

Revert lib changes. Add changes to testMessage

Signed-off-by: Abhinav Pandey <[email protected]>

Update testMessage for compositeRate.js

Signed-off-by: Abhinav Pandey <[email protected]>

Update tsxStats for compositeRate.js

Signed-off-by: Abhinav Pandey <[email protected]>

Update LICENSE

Signed-off-by: Abhinav Pandey <[email protected]>

Update Imports for compositeRate.js

Missing Functions in codebase causing errors

Signed-off-by: Abhinav Pandey <[email protected]>
  • Loading branch information
Sweetdevil144 committed May 11, 2024
1 parent d029784 commit c8a609f
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions packages/caliper-core/test/worker/rate-control/compositeRate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,16 @@

const chai = require('chai');
const expect = chai.expect;
const CompositeRateController = require('../../../lib/worker/rate-control/compositeRate.js');
const { createRateController } = require('../../../lib/worker/rate-control/compositeRate.js');
// const RateControl = require('../../../lib/worker/rate-control/rateControl.js');
// const TransactionStatisticsCollector = require('../../../lib/common/core/transaction-statistics-collector');
const TransactionStatisticsCollector = require('../../../lib/common/core/transaction-statistics-collector');
const TestMessage = require('../../../lib/common/messages/testMessage.js');

/**
* Encapsulates a controller and its scheduling information.
*
* @property {boolean} isLast Indicates whether the controller is the last in the round.
* @property {RateControl} controller The controller instance.
* @property {number} lastTxIndex The last TX index associated with the controller based on its weight. Only used in Tx number-based rounds.
* @property {number} relFinishTime The finish time of the controller based on its weight, relative to the start time of the round. Only used in duration-based rounds.
* @property {TransactionStatisticsCollector} txStatSubCollector The TX stat (sub-)collector associated with the sub-controller.
*/

describe('CompositeRateController', () => {
let testMessage;
let CompositeRateController;
let stats;
beforeEach(() => {
let msgContent = {
label: 'query2',
Expand All @@ -48,19 +41,18 @@ describe('CompositeRateController', () => {
totalWorkers: 2,
weights: [1],
rateControllers: ['composite-rate'],
workerArgs: 0,
numb: 0
};
testMessage = new TestMessage('test', [], msgContent);
stats = new TransactionStatisticsCollector(0, 0, 'query2');
CompositeRateController = createRateController(testMessage, stats, 0);
});

describe('Initialization', () => {
describe('#constructor', () => {
it('should correctly initialize with default settings', () => {
const testMessage = new TestMessage('test', [], {
weights: [1],
rateControllers: ['fixed-rate']
});
const controller = new CompositeRateController(testMessage, {}, 0);
expect(controller.activeControllerIndex).to.equal(0);
expect(controller.controllers.length).to.equal(1);
expect(CompositeRateController.activeControllerIndex).to.equal(0);
expect(CompositeRateController.controllers.length).to.equal(0);
});
});

Expand All @@ -75,15 +67,15 @@ describe('CompositeRateController', () => {
testMessage.content.weights = 'not an array';
testMessage.content.rateControllers = 'not an array';
expect(() =>
CompositeRateController.createRateController(testMessage, {}, 0)
CompositeRateController.createRateController(testMessage, stats, 0)
).to.throw('Weight and controller definitions must be arrays.');
});

it('should throw error when weights and rateControllers lengths are not the same', async () => {
testMessage.content.weights = [1, 2];
testMessage.content.rateControllers = ['composite-rate'];
expect(() =>
CompositeRateController.createRateController(testMessage, {}, 0)
CompositeRateController.createRateController(testMessage, stats, 0)
).to.throw(
'The number of weights and controllers must be the same.'
);
Expand All @@ -93,23 +85,23 @@ describe('CompositeRateController', () => {
testMessage.content.weights = [1, 'not a number'];
testMessage.content.rateControllers = ['composite-rate', 'composite-rate'];
expect(() =>
CompositeRateController.createRateController(testMessage, {}, 0)
CompositeRateController.createRateController(testMessage, stats, 0)
).to.throw('Not-a-number element among weights: not a number');
});

it('should throw error when weights contains negative number', async () => {
testMessage.content.weights = [1, -2];
testMessage.content.rateControllers = ['composite-rate', 'composite-rate'];
expect(() =>
CompositeRateController.createRateController(testMessage, {}, 0)
CompositeRateController.createRateController(testMessage, stats, 0)
).to.throw('Negative element among weights: -2');
});

it('should throw error when all weights are zero', async () => {
testMessage.content.weights = [0, 0];
testMessage.content.rateControllers = ['composite-rate', 'composite-rate'];
expect(() =>
CompositeRateController.createRateController(testMessage, {}, 0)
CompositeRateController.createRateController(testMessage, stats, 0)
).to.throw('Every weight is zero.');
});
});
Expand Down

0 comments on commit c8a609f

Please sign in to comment.