Skip to content
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

Merged
merged 3 commits into from
Sep 19, 2016
Merged

oc-client warmup improvements #288

merged 3 commits into from
Sep 19, 2016

Conversation

matteofigus
Copy link
Member

This PR is for improving the warmup mechanism in the oc node.js client

  • Some unit tests to cover the basic functional aspects
  • Fixed a little bug that in some scenarios could generate wrong urls to warmup
  • More detailed error log in case of failing request

@matteofigus matteofigus changed the title Warmup error details and stuff oc-client warmup improvements Sep 15, 2016
Copy link
Member

@mattiaerre mattiaerre left a 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 ' +
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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(){
Copy link
Member

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){
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Member

@mattiaerre mattiaerre left a 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;
Copy link
Member

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?

Copy link
Member Author

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).

Copy link
Member

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)';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that 👍

Copy link
Member

@mattiaerre mattiaerre left a 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;
Copy link
Member

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!

@matteofigus
Copy link
Member Author

merging as I got the reviewers 👍

@matteofigus matteofigus merged commit 47586e5 into master Sep 19, 2016
@matteofigus matteofigus deleted the client-warmup branch September 19, 2016 09:29
@matteofigus matteofigus mentioned this pull request Sep 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants