-
Notifications
You must be signed in to change notification settings - Fork 122
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
oc-client warmup improvements #288
Conversation
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.
I've done w/ my review; over to you @matteofigus
|
||
it('should return an error with all the details', function(){ | ||
|
||
var expectedError = 'Error: Error warming up oc-client: request ' + |
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 about reusing the settings.js file here as well as the "template" for the error?
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.
This is consistent with the other test. I don't mind tests being a bit verbose and dirty if it improves readability.
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.
I cleaned up that to be a bit more readable btw hopefully it is better
var injectr = require('injectr'); | ||
var sinon = require('sinon'); | ||
|
||
describe('client : warmup', function(){ |
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.
well done w/ the tests; they helped me to understand what the feature does
@@ -17,12 +17,12 @@ var _ = { | |||
eachAsync: function(obj, fn, cb){ | |||
var c = obj.length; | |||
|
|||
var next = function(){ | |||
var next = function(err){ |
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.
in this case, the variable names are not helping very much w/ readability aren't they?
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.
True. This is really just a little custom polyfill for some little async functions that I use - mostly to keep the client as much "dependency free" and small as possible. The behaviour I changed here is that for a group of parallel async tasks, I want the cycle to exit not only when all the tasks are done - but also when any of the tasks errors via "calling back" an error.
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.
Renamed vars a bit to improve readability, hopefully this is a bit better
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.
over to you @matteofigus
callbacksLeft--; | ||
if(callbacksLeft === 0 || !!err){ | ||
|
||
var cbCopy = cb; |
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.
I do not quite understand why you do cbCopy (not entirely sure you do copy it btw) and also you do _.noop ... can you explain as I am really curious about it?
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.
This 2 lines are to ensure main callback is called just once. So basically I am overriding main callback with noop (function(){}) so that future executions do nothing. This is mostly for handling the scenario of when I fire the callback as soon as the error happens (so, other things could complete later but I ignore them).
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.
I understand, all good to me then; thanks!
timeout: 5 | ||
}; | ||
|
||
var expectedError = 'Error: Error warming up oc-client: request ' + JSON.stringify(expectedRequest) + ' failed (timeout)'; |
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.
I like that 👍
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.
LGTM
callbacksLeft--; | ||
if(callbacksLeft === 0 || !!err){ | ||
|
||
var cbCopy = cb; |
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.
I understand, all good to me then; thanks!
merging as I got the reviewers 👍 |
This PR is for improving the warmup mechanism in the oc node.js client