Skip to content

Commit 089991f

Browse files
committed
Improve code from review
Issue: S3UTILS-188
1 parent 84a25e2 commit 089991f

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

CountItems/utils/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ function consolidateDataMetrics(target, source) {
8282
return resTarget;
8383
}
8484

85-
8685
function serializeBigInts(obj) {
8786
if (typeof obj !== 'object' || obj === null) {
8887
return typeof obj === 'bigint' ? { __bigint: obj.toString() } : obj;

tests/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ module.exports = {
2424
_lifecycleConfiguration: null,
2525
_uid: '',
2626
_isNFS: null,
27+
_capabilities: {
28+
VeeamSOSApi: undefined,
29+
},
2730
ingestion: null,
2831
},
2932
testAccountCanonicalId: 'd1d40abd2bd8250962f7f5774af1bbbeaec9b77a0853749d41ec46f142e66fe4',

tests/functional/collectBucketMetricsAndUpdateBucketCapacityInfo.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ describe('collectBucketMetricsAndUpdateBucketCapacityInfo', () => {
9494
next();
9595
}),
9696
next => client.getBucketAttributes(testBucketName, logger, (err, bucketInfo) => {
97-
assert.equal(err && err.message, 'InternalError');
98-
assert.equal(bucketInfo, undefined);
97+
assert.equal(err, null);
98+
assert.strictEqual(bucketInfo.getCapabilities().VeeamSOSApi, undefined);
9999
next();
100100
}),
101101
], done);
@@ -169,7 +169,7 @@ describe('collectBucketMetricsAndUpdateBucketCapacityInfo', () => {
169169
});
170170

171171
test('should update bucket Capacity and Available -1 if Capacity value is not set', done => {
172-
testBucketCapacities.VeeamSOSApi.CapacityInfo.Capacity = -1;
172+
testBucketCapacities.VeeamSOSApi.CapacityInfo.Capacity = -1n;
173173

174174
return async.series([
175175
next => client.createBucket(testBucketName, {

tests/functional/utils/S3UtilsMongoClient.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ describe('S3UtilsMongoClient::getObjectMDStats', () => {
464464
logger,
465465
(err, data) => {
466466
assert.deepStrictEqual(err, null);
467-
// assert.deepStrictEqual(data, expected);\
468467
// Compare each section separately to avoid circular reference issues
469468
assert.strictEqual(data.versions.toString(), expected.versions.toString());
470469
assert.strictEqual(data.objects.toString(), expected.objects.toString());
@@ -1613,7 +1612,7 @@ describe('S3UtilsMongoClient::getObjectMDStats', () => {
16131612
});
16141613
});
16151614

1616-
describe.skip('S3UtilsMongoClient::updateBucketCapacityInfo', () => {
1615+
describe('S3UtilsMongoClient::updateBucketCapacityInfo', () => {
16171616
let client;
16181617
let repl;
16191618

@@ -1676,7 +1675,7 @@ describe.skip('S3UtilsMongoClient::updateBucketCapacityInfo', () => {
16761675
});
16771676
});
16781677

1679-
describe.skip('S3UtilsMongoClient::getBucketInfos', () => {
1678+
describe('S3UtilsMongoClient::getBucketInfos', () => {
16801679
let client;
16811680
let repl;
16821681

@@ -1731,9 +1730,18 @@ describe.skip('S3UtilsMongoClient::getBucketInfos', () => {
17311730
it('Should get correct bucket infos', done => client.getBucketInfos(logger, (err, data) => {
17321731
assert.equal(err, null);
17331732
assert.strictEqual(data.bucketCount, 3);
1734-
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[0]._name)), JSON.stringify(buckets[0]));
1735-
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[1]._name)), JSON.stringify(buckets[1]));
1736-
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[2]._name)), JSON.stringify(buckets[2]));
1733+
assert.strictEqual(
1734+
data.bucketInfos.find(bucket => bucket._name === buckets[0]._name).serialize(),
1735+
BucketInfo.fromObj(buckets[0]).serialize(),
1736+
);
1737+
assert.strictEqual(
1738+
data.bucketInfos.find(bucket => bucket._name === buckets[1]._name).serialize(),
1739+
BucketInfo.fromObj(buckets[1]).serialize(),
1740+
);
1741+
assert.strictEqual(
1742+
data.bucketInfos.find(bucket => bucket._name === buckets[2]._name).serialize(),
1743+
BucketInfo.fromObj(buckets[2]).serialize(),
1744+
);
17371745
done();
17381746
}));
17391747

@@ -1758,9 +1766,9 @@ describe.skip('S3UtilsMongoClient::getBucketInfos', () => {
17581766

17591767
// Perform the assertions
17601768
assert.strictEqual(data.bucketCount, 2);
1761-
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[0]._name)), undefined);
1762-
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[1]._name)), JSON.stringify(buckets[1]));
1763-
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[2]._name)), JSON.stringify(buckets[2]));
1769+
assert.strictEqual(data.bucketInfos.find(bucket => bucket._name === buckets[0]._name), undefined);
1770+
assert.strictEqual(!!data.bucketInfos.find(bucket => bucket._name === buckets[1]._name), true);
1771+
assert.strictEqual(!!data.bucketInfos.find(bucket => bucket._name === buckets[2]._name), true);
17641772
});
17651773
});
17661774
});

utils/S3UtilsMongoClient.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const INFOSTORE_TMP = `${INFOSTORE}_tmp`;
1414
const __COUNT_ITEMS = 'countitems';
1515

1616
const BigIntMax = (...args) => args.reduce((max, current) => {
17-
const maxAsBigInt = typeof max === 'bigint' ? max : BigInt(max);
18-
const currentAsBigInt = typeof current === 'bigint' ? current : BigInt(current);
17+
const maxAsBigInt = BigInt(max);
18+
const currentAsBigInt = BigInt(current);
1919
return maxAsBigInt > currentAsBigInt ? max : current;
2020
});
2121

@@ -114,7 +114,7 @@ class S3UtilsMongoClient extends MongoClientInterface {
114114
const id = entry._id;
115115
if (id.startsWith('bucket_')) {
116116
const inflightDocument = inflightsMap[id];
117-
const inflight = inflightDocument ? BigIntMax(0, inflightDocument - entry.usedCapacity._inflightsPreScan) : 0n;
117+
const inflight = inflightDocument ? BigIntMax(0n, inflightDocument - entry.usedCapacity._inflightsPreScan) : 0n;
118118
if (inflight) {
119119
// Inflights remaining after the scan are part of the "current" bytes,
120120
// and stored in _inflightsDelta

0 commit comments

Comments
 (0)