-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for rate-control/compositeRate.js
#1572
base: main
Are you sure you want to change the base?
Add tests for rate-control/compositeRate.js
#1572
Conversation
Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in>
Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in> Update compositeRate.js Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in> Revert unnecessary logs Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in> Revert lib changes. Add changes to testMessage Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in> Update testMessage for compositeRate.js Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in> Update tsxStats for compositeRate.js Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in> Update LICENSE Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in> Update Imports for compositeRate.js Missing Functions in codebase causing errors Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in>
f2a9b6f
to
c8a609f
Compare
Somehow, recursive calling occurs when these changes were made Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in>
Considering above changes have been applied for proper data-handling within
|
@davidkel can you help me with this in any way possible? |
@Sweetdevil144 Unfortunately your change is not correct. The reason you are getting an error and options is an empty object is because that's what you have set it to in your test when you created a mock message.
|
Thanks. The test cases work fine now. However, I found a bug within our I notices that we had been extracting let weights = this.options.weights;
let rateControllers = this.options.rateControllers; Whereas, it should have been as below : let weights = this.testMessage.content.weights;
let rateControllers = this.testMessage.content.rateControllers; Can you confirm whether I'm correct or not @davidkel ? I'm pushing the overall applied changes for now. I'll refract them if you feel these aren't corresponding to any internal bug in system. |
Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in>
Final cleanup completed Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in>
@Sweetdevil144 Sorry, no your change is not correct. Not sure how you have come to this conclusion but if you look in the documentation https://hyperledger.github.io/caliper/v0.6.0/rate-controllers/#composite-rate you will see the format of the rate controller spec. weights and rateControllers are properties of |
Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in>
…/caliper into test-compositeRate
@davidkel fixed. Can you review it? |
Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in>
Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we want to try to replicate is the pattern used for writing unit tests as seen in the caliper-fabric
package. For example you will see we don't use any method names in the describe or it descriptions, no internal methods are explicitly tested.
Unfortunately the patterns used in other parts of Caliper are from the old way of thinking but it would be a lot of work to go back and refactor the existing tests, but we want to try to make sure that all new tests are done in the new style.
packages/caliper-core/test/worker/rate-control/compositeRate.js
Outdated
Show resolved
Hide resolved
}); | ||
}); | ||
|
||
describe('#_prepareControllers', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to be directly testing internal methods (ie ones that start with _
). All tests should drive the public apis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we incorporate _prepareControllers
within applyRateControl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessarily about incorporating especially if the internal method is called from multiple public methods. You need to write tests that make sense for the public methods and if the internal method gets called multiple times by the tests then that's fine. As an example a public method which has multiple code flows but to test all those code flows you may end up always calling the private method which is expected.
}); | ||
}); | ||
|
||
describe('#_controllerSwitchForDuration', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to be directly testing internal methods (ie ones that start with _
). All tests should drive the public apis.
Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in>
Signed-off-by: Abhinav Pandey <abhinav.pandey.met22@itbhu.ac.in>
…/caliper into test-compositeRate
This PR aims to create unit-tests for
compositeRate.js
class within ourcaliper-core
package.However, the current tests are failing due to following reasons.
Within our
packages/caliper-core/lib/worker/rate-control/compositeRate.js
, we find the following line :https://github.com/hyperledger/caliper/blob/21a98f496c850840c211a670c32fcfa9240612bb/packages/caliper-core/lib/worker/rate-control/compositeRate.js#L76
However, I tried logging out
this.options
and was returned with an empty Object as output.I was returned with following logs :
Due to this our initial check at line 86, that is :
https://github.com/hyperledger/caliper/blob/21a98f496c850840c211a670c32fcfa9240612bb/packages/caliper-core/lib/worker/rate-control/compositeRate.js#L79
Always throws an error. However, if we replace the line 76 above with
Then, our tests pass.
What would be the most optimum fix for such cases?
Checklist
Issue/User story
Steps to Reproduce
Existing issues
This issue is a small part of #1557 which aims to increase overall code-coverage for the
caliper-core
package.