Skip to content

Commit

Permalink
adding tests post reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Jul 22, 2024
1 parent 11f5370 commit 2f37bcd
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 1 deletion.
20 changes: 19 additions & 1 deletion extensions/gc/tasks/GarbageCollectorTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class GarbageCollectorTask extends BackbeatTask {
});
}

_executeDeleteData(entry, log, done) {
_executeDeleteDataOnce(entry, log, done) {
const { locations } = entry.getAttribute('target');
const ruleType = entry.getContextAttribute('ruleType');
const params = {
Expand Down Expand Up @@ -184,6 +184,24 @@ class GarbageCollectorTask extends BackbeatTask {
});
}

_executeDeleteData(entry, log, done) {
const logFields = {
bucket: entry.getAttribute('source.bucket'),
objectKey: entry.getAttribute('source.objectKey'),
storageClass: entry.getAttribute('source.storageClass'),
ruleType: entry.getContextAttribute('ruleType'),
};

this.retry({
actionDesc: 'execute delete data',
logFields,
maxRetries: 2,
actionFunc: cb => this._executeDeleteDataOnce(entry, log, cb),
shouldRetryFunc: err => err.retryable,
log,
}, done);
}

_deleteArchivedSourceDataOnce(entry, log, done) {
const { bucket, key, version, oldLocation, newLocation } = entry.getAttribute('target');

Expand Down
90 changes: 90 additions & 0 deletions tests/unit/gc/GarbageCollectorTask.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,94 @@ describe('GarbageCollectorTask', () => {
done();
});
});

it('should delete data', done => {
backbeatClient.batchDeleteResponse = { error: null, res: null };

const entry = ActionQueueEntry.create('deleteData')
.addContext({
origin: 'lifecycle',
ruleType: 'expiration',
bucketName: bucket,
objectKey: key,
versionId: version,
})
.setAttribute('serviceName', 'lifecycle-expiration')
.setAttribute('target', {
bucket: bucket,

Check failure on line 283 in tests/unit/gc/GarbageCollectorTask.spec.js

View workflow job for this annotation

GitHub Actions / tests

Expected property shorthand
key: version,
version: key,
accountId: accountId,

Check failure on line 286 in tests/unit/gc/GarbageCollectorTask.spec.js

View workflow job for this annotation

GitHub Actions / tests

Expected property shorthand
owner: owner,

Check failure on line 287 in tests/unit/gc/GarbageCollectorTask.spec.js

View workflow job for this annotation

GitHub Actions / tests

Expected property shorthand
locations: [{

Check failure on line 288 in tests/unit/gc/GarbageCollectorTask.spec.js

View workflow job for this annotation

GitHub Actions / tests

Trailing spaces not allowed
key: 'locationKey',
dataStoreName: 'dataStoreName',
size: 'size',
dataStoreVersionId: 'dataStoreVersionId',
}],
});
mdObj.setLocation(loc)
.setDataStoreName('locationName')
.setAmzStorageClass('STANDARD');

backbeatMetadataProxyClient.setMdObj(mdObj);

const batchDeleteDataSpy = sinon.spy(gcTask, '_batchDeleteData');

gcTask.processActionEntry(entry, (err, commitInfo) => {
assert.ifError(err);
assert.strictEqual(commitInfo, undefined);

const updatedMD = backbeatMetadataProxyClient.mdObj;
assert.deepStrictEqual(updatedMD.getLocation(), loc);
assert.strictEqual(updatedMD.getDataStoreName(), 'locationName');
assert.strictEqual(updatedMD.getAmzStorageClass(), 'STANDARD');

assert.strictEqual(batchDeleteDataSpy.callCount, 1);
batchDeleteDataSpy.restore();
done();
});
});

it('should retry delete operation if gc failed with retryable error', done => {
backbeatClient.batchDeleteResponse = { error: { statusCode: 500, retryable: true }, res: null };

const entry = ActionQueueEntry.create('deleteData')
.addContext({
origin: 'lifecycle',
ruleType: 'expiration',
bucketName: bucket,
objectKey: key,
versionId: version,
})
.setAttribute('serviceName', 'lifecycle-expiration')
.setAttribute('target', {
bucket: bucket,

Check failure on line 331 in tests/unit/gc/GarbageCollectorTask.spec.js

View workflow job for this annotation

GitHub Actions / tests

Expected property shorthand
key: version,
version: key,
accountId: accountId,

Check failure on line 334 in tests/unit/gc/GarbageCollectorTask.spec.js

View workflow job for this annotation

GitHub Actions / tests

Expected property shorthand
owner: owner,

Check failure on line 335 in tests/unit/gc/GarbageCollectorTask.spec.js

View workflow job for this annotation

GitHub Actions / tests

Expected property shorthand
locations: [{

Check failure on line 336 in tests/unit/gc/GarbageCollectorTask.spec.js

View workflow job for this annotation

GitHub Actions / tests

Trailing spaces not allowed
key: 'locationKey',
dataStoreName: 'dataStoreName',
size: 'size',
dataStoreVersionId: 'dataStoreVersionId',
}],
});
mdObj.setLocation(loc)
.setDataStoreName('locationName')
.setAmzStorageClass('STANDARD');

backbeatMetadataProxyClient.setMdObj(mdObj);

const batchDeleteDataSpy = sinon.spy(gcTask, '_batchDeleteData');

gcTask.processActionEntry(entry, (err) => {

Check warning on line 351 in tests/unit/gc/GarbageCollectorTask.spec.js

View workflow job for this annotation

GitHub Actions / tests

Unexpected parentheses around single function argument
assert.strictEqual(batchDeleteDataSpy.callCount, 3);
assert.strictEqual(err.statusCode, 500);
batchDeleteDataSpy.restore();
done();
});
});

});

0 comments on commit 2f37bcd

Please sign in to comment.