Skip to content

Commit

Permalink
fix: fix logic for buckets that do not have a generation (#1634)
Browse files Browse the repository at this point in the history
* fix: fix logic for buckets that do not have a generation

* add test for autoRetry remaining true
  • Loading branch information
ddelgrosso1 committed Oct 1, 2021
1 parent b841d5b commit 9069bdc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4075,15 +4075,8 @@ class Bucket extends ServiceObject {
if (
typeof coreOpts === 'object' &&
coreOpts?.reqOpts?.qs?.ifMetagenerationMatch === undefined &&
methodType === AvailableServiceObjectMethods.setMetadata &&
this.storage.retryOptions.idempotencyStrategy ===
IdempotencyStrategy.RetryConditional
) {
this.storage.retryOptions.autoRetry = false;
} else if (
typeof coreOpts === 'object' &&
coreOpts?.reqOpts?.qs?.ifGenerationMatch === undefined &&
methodType === AvailableServiceObjectMethods.delete &&
(methodType === AvailableServiceObjectMethods.setMetadata ||
methodType === AvailableServiceObjectMethods.delete) &&
this.storage.retryOptions.idempotencyStrategy ===
IdempotencyStrategy.RetryConditional
) {
Expand Down
55 changes: 55 additions & 0 deletions test/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
SetBucketMetadataCallback,
SetBucketMetadataResponse,
GetBucketSignedUrlConfig,
AvailableServiceObjectMethods,
} from '../src/bucket';
import {AddAclOptions} from '../src/acl';
import {Policy} from '../src/iam';
Expand Down Expand Up @@ -3237,4 +3238,58 @@ describe('Bucket', () => {
);
});
});
describe('disableAutoRetryConditionallyIdempotent_', () => {
beforeEach(() => {
bucket.storage.retryOptions.autoRetry = true;
STORAGE.retryOptions.idempotencyStrategy =
IdempotencyStrategy.RetryConditional;
});

it('should set autoRetry to false when ifMetagenerationMatch is undefined (setMetadata)', done => {
bucket.disableAutoRetryConditionallyIdempotent_(
bucket.methods.setMetadata,
AvailableServiceObjectMethods.setMetadata
);
assert.strictEqual(bucket.storage.retryOptions.autoRetry, false);
done();
});

it('should set autoRetry to false when ifMetagenerationMatch is undefined (delete)', done => {
bucket.disableAutoRetryConditionallyIdempotent_(
bucket.methods.delete,
AvailableServiceObjectMethods.delete
);
assert.strictEqual(bucket.storage.retryOptions.autoRetry, false);
done();
});

it('should set autoRetry to false when IdempotencyStrategy is set to RetryNever', done => {
STORAGE.retryOptions.idempotencyStrategy = IdempotencyStrategy.RetryNever;
bucket = new Bucket(STORAGE, BUCKET_NAME, {
preconditionOpts: {
ifMetagenerationMatch: 100,
},
});
bucket.disableAutoRetryConditionallyIdempotent_(
bucket.methods.delete,
AvailableServiceObjectMethods.delete
);
assert.strictEqual(bucket.storage.retryOptions.autoRetry, false);
done();
});

it('autoRetry should remain true when ifMetagenerationMatch is not undefined', done => {
bucket = new Bucket(STORAGE, BUCKET_NAME, {
preconditionOpts: {
ifMetagenerationMatch: 100,
},
});
bucket.disableAutoRetryConditionallyIdempotent_(
bucket.methods.delete,
AvailableServiceObjectMethods.delete
);
assert.strictEqual(bucket.storage.retryOptions.autoRetry, true);
done();
});
});
});

0 comments on commit 9069bdc

Please sign in to comment.