Skip to content

Commit

Permalink
Improve code from review
Browse files Browse the repository at this point in the history
  • Loading branch information
williamlardier committed Jan 28, 2025
1 parent 13b170a commit fadd578
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
1 change: 0 additions & 1 deletion CountItems/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ function consolidateDataMetrics(target, source) {
return resTarget;
}


function serializeBigInts(obj) {
if (typeof obj !== 'object' || obj === null) {
return typeof obj === 'bigint' ? { __bigint: obj.toString() } : obj;
Expand Down
3 changes: 3 additions & 0 deletions tests/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ module.exports = {
_lifecycleConfiguration: null,
_uid: '',
_isNFS: null,
_capabilities: {
VeeamSOSApi: undefined,
},
ingestion: null,
},
testAccountCanonicalId: 'd1d40abd2bd8250962f7f5774af1bbbeaec9b77a0853749d41ec46f142e66fe4',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ describe('collectBucketMetricsAndUpdateBucketCapacityInfo', () => {
next();
}),
next => client.getBucketAttributes(testBucketName, logger, (err, bucketInfo) => {
assert.equal(err && err.message, 'InternalError');
assert.equal(bucketInfo, undefined);
assert.equal(err, null);
assert.strictEqual(bucketInfo.getCapabilities().VeeamSOSApi, undefined);
next();
}),
], done);
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('collectBucketMetricsAndUpdateBucketCapacityInfo', () => {
});

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

return async.series([
next => client.createBucket(testBucketName, {
Expand Down
26 changes: 17 additions & 9 deletions tests/functional/utils/S3UtilsMongoClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ describe('S3UtilsMongoClient::getObjectMDStats', () => {
logger,
(err, data) => {
assert.deepStrictEqual(err, null);
// assert.deepStrictEqual(data, expected);\
// Compare each section separately to avoid circular reference issues
assert.strictEqual(data.versions.toString(), expected.versions.toString());
assert.strictEqual(data.objects.toString(), expected.objects.toString());
Expand Down Expand Up @@ -1613,7 +1612,7 @@ describe('S3UtilsMongoClient::getObjectMDStats', () => {
});
});

describe.skip('S3UtilsMongoClient::updateBucketCapacityInfo', () => {
describe('S3UtilsMongoClient::updateBucketCapacityInfo', () => {
let client;
let repl;

Expand Down Expand Up @@ -1676,7 +1675,7 @@ describe.skip('S3UtilsMongoClient::updateBucketCapacityInfo', () => {
});
});

describe.skip('S3UtilsMongoClient::getBucketInfos', () => {
describe('S3UtilsMongoClient::getBucketInfos', () => {
let client;
let repl;

Expand Down Expand Up @@ -1731,9 +1730,18 @@ describe.skip('S3UtilsMongoClient::getBucketInfos', () => {
it('Should get correct bucket infos', done => client.getBucketInfos(logger, (err, data) => {
assert.equal(err, null);
assert.strictEqual(data.bucketCount, 3);
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[0]._name)), JSON.stringify(buckets[0]));
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[1]._name)), JSON.stringify(buckets[1]));
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[2]._name)), JSON.stringify(buckets[2]));
assert.strictEqual(
data.bucketInfos.find(bucket => bucket._name === buckets[0]._name).serialize(),
BucketInfo.fromObj(buckets[0]).serialize(),
);
assert.strictEqual(
data.bucketInfos.find(bucket => bucket._name === buckets[1]._name).serialize(),
BucketInfo.fromObj(buckets[1]).serialize(),
);
assert.strictEqual(
data.bucketInfos.find(bucket => bucket._name === buckets[2]._name).serialize(),
BucketInfo.fromObj(buckets[2]).serialize(),
);
done();
}));

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

// Perform the assertions
assert.strictEqual(data.bucketCount, 2);
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[0]._name)), undefined);
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[1]._name)), JSON.stringify(buckets[1]));
assert.strictEqual(JSON.stringify(data.bucketInfos.find(bucket => bucket._name === buckets[2]._name)), JSON.stringify(buckets[2]));
assert.strictEqual(data.bucketInfos.find(bucket => bucket._name === buckets[0]._name), undefined);
assert.strictEqual(!!data.bucketInfos.find(bucket => bucket._name === buckets[1]._name), true);
assert.strictEqual(!!data.bucketInfos.find(bucket => bucket._name === buckets[2]._name), true);
});
});
});
6 changes: 3 additions & 3 deletions utils/S3UtilsMongoClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const INFOSTORE_TMP = `${INFOSTORE}_tmp`;
const __COUNT_ITEMS = 'countitems';

const BigIntMax = (...args) => args.reduce((max, current) => {
const maxAsBigInt = typeof max === 'bigint' ? max : BigInt(max);
const currentAsBigInt = typeof current === 'bigint' ? current : BigInt(current);
const maxAsBigInt = BigInt(max);
const currentAsBigInt = BigInt(current);
return maxAsBigInt > currentAsBigInt ? max : current;
});

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

0 comments on commit fadd578

Please sign in to comment.