-
Notifications
You must be signed in to change notification settings - Fork 56
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 smart retries to table.mutate #17
Add smart retries to table.mutate #17
Conversation
Codecov Report
@@ Coverage Diff @@
## master #17 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 8 8
Lines 792 811 +19
=====================================
+ Hits 792 811 +19
Continue to review full report at Codecov.
|
f3e988f
to
c675798
Compare
I can get coverage for unit tests back to 100% with the following patch, although I'm not sure it's the right thing to do diff --git a/test/table.js b/test/table.js
index f348120..9173788 100644
--- a/test/table.js
+++ b/test/table.js
@@ -999,8 +999,10 @@ describe('Bigtable/Table', function() {
describe('error', function() {
describe('API errors', function() {
var error = new Error('err');
+ var setTimeoutStub;
beforeEach(function() {
+ setTimeoutStub = sinon.stub(global, 'setTimeout').callsFake(setImmediate);
table.requestStream = function() {
var stream = new Stream({
objectMode: true,
@@ -1015,6 +1017,10 @@ describe('Bigtable/Table', function() {
};
});
+ afterEach(function() {
+ setTimeoutStub.restore();
+ });
+
it('should return the error to the callback', function(done) {
table.maxRetries = 0;
table.mutate(entries, function(err) {
@@ -1022,6 +1028,17 @@ describe('Bigtable/Table', function() {
done();
});
});
+
+ it('attempts to retry the mutation', function(done) {
+ table.maxRetries = 1;
+ table.mutate(entries, function(err) {
+ assert.strictEqual(err, error);
+ assert.strictEqual(setTimeoutStub.callCount, 1);
+ assert(setTimeoutStub.getCall(0).args[1] > 2000);
+ assert(setTimeoutStub.getCall(0).args[1] < 3000);
+ done();
+ });
+ });
});
describe('mutation errors', function() { |
c675798
to
9e189b3
Compare
9e189b3
to
41be320
Compare
This PR introduces an "integration" test command, but we already have system tests that are supposed to be the same thing: "Does our code work when integrated with the system?" (Using the name "system tests" was a decision that involved more languages than just us). I also see a reference to "acceptance" testing. I think we should keep everything under one roof, "system tests", since that's our pattern across all of the API libraries. It should only be one command for a contributor/maintainer to determine if their changes introduce any issues with the upstream API, and that's historically been "npm run system-test". Regarding the patching, I would prefer to wait for calvinmetcalf/process-nextick-args#10 to be merged and released. |
package.json
Outdated
@@ -78,6 +81,7 @@ | |||
"eslint-config-prettier": "^2.6.0", | |||
"eslint-plugin-node": "^5.2.0", | |||
"eslint-plugin-prettier": "^2.3.1", | |||
"grpc": "^1.7.2", |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/table.js
Outdated
if (pendingEntryIndices.size !== 0 && requestsMade <= maxRetries) { | ||
setTimeout( | ||
makeNextRequestBatch, | ||
retryRequest.getNextRetryDelay(requestsMade) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Regarding patching, after calvinmetcalf/process-nextick-args#10 is merged (it already was), nodejs/readable-stream#317 needs to be merged, publish a release (note this module is basically part of node core), and then wait for |
I see, thanks for the rundown. Yeah, I suppose the patching will have to do for now. |
This is to enable not needing to call setTimeout when making a followup request. See googleapis/nodejs-bigtable#17 (comment) for more details
This is to enable not needing to call setTimeout when making a followup request. See googleapis/nodejs-bigtable#17 (comment) for more details
57bba9b
to
5fa4aa6
Compare
Thanks for splitting that out. I believe there might be some work for the code coverage still. https://codecov.io/gh/googleapis/nodejs-bigtable/pull/17/src/src/table.js?before=src/table.js#L942 |
I can add the following test to the unit tests to get it back to 100%. Is that something you'd be ok with? describe('retries', function() {
var fakeStatuses = [
[
{
status: {
code: 0,
},
},
{
status: {
code: 4,
},
},
],
[
{
status: {
code: 0,
},
},
]
];
beforeEach(function() {
FakeGrpcService.decorateStatus_ = function(status) {
return {};
};
table.requestStream = function() {
var stream = new Stream({
objectMode: true,
});
setImmediate(function() {
stream.emit('request');
stream.end({entries: fakeStatuses.shift()});
});
return stream;
};
});
it('should succeed after a retry', function(done) {
table.maxRetries = 1;
table.mutate(entries, done);
});
});
}); |
That test looks good to me. I also think we should have another unit test to confirm only the correct subset of entries from the original request is sent when a retry is made, effectively testing the new |
e561e4f
to
46a41ad
Compare
46a41ad
to
e622bcd
Compare
Done, coverage appears to be back to 100% |
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
I made some small changes, just to conventionalize the code (stream error handling first, all caps file-wide const name, etc). Tests still pass, but please make sure these changes look harmless to you as well. |
Look good to me! |
This is to enable not needing to call setTimeout when making a followup request. See googleapis/nodejs-bigtable#17 (comment) for more details
A couple of things to note about this PR:
v4
has a nested node_modules structure while>= v6
is flat.patch-package
doesn't handle possible missing packages so that's why the git commands are run manually