Skip to content

Commit

Permalink
S3UTILS-148: update tests and stalled with mongodb breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
williamlardier committed Oct 12, 2023
1 parent aa74440 commit 766f4cb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
17 changes: 9 additions & 8 deletions StalledRetry/MongoClientInterfaceStalled.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ class MongoClientInterfaceStalled extends MongoClientInterface {
},
},
{ $project: reducedFields },
]);
]).stream();
}

queueStalledObjects(expiredBy, cb) {
async queueStalledObjects(expiredBy, cb) {
const cmpDate = new Date();
cmpDate.setHours(cmpDate.getHours() - expiredBy);
const reqHandler = this.requestHandlerFactory(this.logger);

let stalledCount = 0;
this.db.listCollections().toArray((err, collections) => {
if (err) {
return cb(err);
}
try {
const collections = await this.db.listCollections().toArray();
let i = 0;
return async.eachSeries(collections, (value, next) => {
i++;
if (this._isSpecialCollection(value.name)) {
// skip
return next();
Expand All @@ -56,7 +56,6 @@ class MongoClientInterfaceStalled extends MongoClientInterface {
this._getStalledObjectsByBucket(bucketName),
this.logger,
);

return reqHandler.handleRequests(wrapper, (err, results) => {
if (err) {
this.logger.error(
Expand All @@ -76,7 +75,9 @@ class MongoClientInterfaceStalled extends MongoClientInterface {
return next();
});
}, err => cb(err, stalledCount));
});
} catch (err) {
return cb(err);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('collectBucketMetricsAndUpdateBucketCapacityInfo', () => {

afterAll(done => {
async.series([
next => client.db.dropDatabase(next),
next => client.db.dropDatabase().then(() => next()).catch(() => next()),
next => client.close(next),
], done);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/countItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('CountItems', () => {

afterAll(done => {
async.series([
next => client.db.dropDatabase(next),
next => client.db.dropDatabase().then(() => next()).catch(() => next()),
next => client.close(next),
], done);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/stalled.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('StalledRetry', () => {

afterAll(done => {
async.series([
next => mgoClient.db.dropDatabase(next),
next => mgoClient.db.dropDatabase().then(() => next()).catch(() => next()),
next => mgoClient.close(next),
], done);
});
Expand Down
29 changes: 20 additions & 9 deletions tests/functional/utils/S3UtilsMongoClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,19 +834,30 @@ describe('S3UtilsMongoClient::getBucketInfos', () => {
done();
}));

it('Should ignore buckets in collection list but not in metastore', done => {
it('Should ignore buckets in collection list but not in metastore', async () => {
const metastoreCollection = client.getCollection('__metastore');
return metastoreCollection.deleteOne({ _id: buckets[0]._name }, err => {
assert.equal(err, null);

// Delete a bucket from the metastore
const deleteResult = await metastoreCollection.deleteOne({ _id: buckets[0]._name });
assert.equal(deleteResult.deletedCount, 1);

// Fetch bucket information
const getBucketInfosPromise = new Promise((resolve, reject) => {
client.getBucketInfos(logger, (err, data) => {
assert.equal(err, null);
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]));
done();
if (err) {
return reject(err);
}
return resolve(data);
});
});

const data = await getBucketInfosPromise;

// 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]));
});
});
});
5 changes: 1 addition & 4 deletions utils/S3UtilsMongoClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,7 @@ class S3UtilsMongoClient extends MongoClientInterface {
async readStorageConsumptionMetrics(entityName, log, cb) {
try {
const i = this.getCollection(INFOSTORE);
const doc = await async.retry(
3,
async () => i.findOne({ _id: entityName }),
);
const doc = await i.findOne({ _id: entityName });
if (!doc) {
return cb(errors.NoSuchEntity);
}
Expand Down

0 comments on commit 766f4cb

Please sign in to comment.