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

new: add inflightRequests() API #181

Merged
merged 5 commits into from Jul 13, 2018
Merged

new: add inflightRequests() API #181

merged 5 commits into from Jul 13, 2018

Conversation

DonutEspresso
Copy link
Member

No description provided.

@coveralls
Copy link

coveralls commented Jul 11, 2018

Coverage Status

Coverage increased (+0.2%) to 87.913% when pulling c2b6fac on inflight-requests into 3d9b330 on master.

Copy link
Contributor

@misterdjules misterdjules left a comment

Choose a reason for hiding this comment

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

Left a few questions but haven't reviewed the newly added tests yet. Will wait for answers to those questions before reviewing them.

README.md Outdated
@@ -470,6 +471,25 @@ client.get(options, function(err, res, socket, head) {
});
```

### More APIs
Copy link
Contributor

Choose a reason for hiding this comment

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

What about "Common APIs" instead of "More APIs"?

README.md Outdated
Returns the number of inflight requests the client is currently handling. An
inflight request is a request that is in any of the following states:

* connection establishment (dns resolution, socket connection, etc.)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add an item "* After the verb function is called but before any I/O (dns resolution, socket connection, etc.) is performed."? It's mentioned below but here it seems this list is meant to be exhaustive, so it seems it'd be misleading to not mention this state as part of the included states.

@@ -268,8 +268,8 @@ function rawRequest(opts, cb) {
req.getMetrics = function getMetrics() {
return metrics;
};
opts.client._inflightRequests--;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be performed by a function that also checks (asserts?) that the number of in-flight requests is e.g. >= 0? I don't think we'd want to check for an upper bound.

@@ -788,6 +793,9 @@ HttpClient.prototype.request = function request(opts, cb) {
assert.object(opts, 'options');
assert.func(cb, 'callback');

var self = this;
self._inflightRequests++;
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that this increments the inflight requests number only for the initial request, but not for retries? On the other hand it seems we decrement number of inflight requests on raw requests' events? If that's correct it seems we'd want that behavior to be symmetrical, otherwise we'd run into cases where the number of inflight requests is < 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great catch! I thought I would catch this with the connection timeout test but it didn't because I set retries: 1 🤦‍♂️

@DonutEspresso
Copy link
Member Author

Thanks for the feedback! Comments addressed, feel free to take another pass at your leisure.

Copy link
Contributor

@misterdjules misterdjules left a comment

Choose a reason for hiding this comment

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

Looks great, left a few minor comments! Thank you!

var self = this;
self._inflightRequests--;
assert.ok(self._inflightRequests >= 0,
'number of inflight requests cannot be <= 0');
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "cannot be < 0".

url: 'http://localhost:3000/',
requestTimeout: 100
});
var STRINGCLIENT = clients.createStringClient({
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we care about testing a JsonClient too?

STRINGCLIENT.get('/200', _.noop);
assert.strictEqual(STRINGCLIENT.inflightRequests(), 4);

setTimeout(function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

On a busy system, it could timeout before all requests and responseshave been processed, and thus could make this test flaky.

What do you think of passing the same callback to all STRINGCLIENT.get calls that would decrement a counter initialized at 4, close the server when that counter reaches 0, and then call done() in the listener for the server's 'close' event?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call. I was being lazy. 👍

@DonutEspresso
Copy link
Member Author

Thanks @misterdjules! Last time around, I hope?

Copy link
Contributor

@misterdjules misterdjules left a comment

Choose a reason for hiding this comment

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

All good once the typo is fixed!

url: 'http://localhost:3000/',
requestTimeout: 100
});
var JSONCLIENT = clients.createStringClient({
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be createJsonClient.

Copy link
Member Author

Choose a reason for hiding this comment

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

😵

Copy link
Contributor

@misterdjules misterdjules left a comment

Choose a reason for hiding this comment

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

🍾

@DonutEspresso DonutEspresso merged commit b86b6d7 into master Jul 13, 2018
@DonutEspresso DonutEspresso deleted the inflight-requests branch July 13, 2018 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants