Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
tmacro committed Oct 9, 2024
1 parent 9ccb24d commit b203f48
Showing 1 changed file with 110 additions and 27 deletions.
137 changes: 110 additions & 27 deletions tests/functional/cron/testReindex.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,41 +183,124 @@ describe('UtapiReindex', () => {
});
});

describe('::_scheduleJob', function test() {
function waitUntilLockHasValue({ value, job }, cb) {
let shouldLeave;
let shouldCallJob = job !== undefined;

async.doUntil(
next =>
redis.get(REINDEX_LOCK_KEY, (err, res) => {
if (err) {
return next(err);
}
if (shouldCallJob) {
job();
shouldCallJob = false;
}
shouldLeave = res === value;
return setTimeout(next, 200);
}),
next => next(null, shouldLeave),
cb,
);
}

function checkMetrics({ resource, expected }, cb) {
utils.listMetrics(resource, (err, res) => {
if (err) {
return cb(err);
}
if (res.code) {
return cb(new Error(res.message));
}
const { storageUtilized, numberOfObjects } = expected;
assert.deepStrictEqual(res[0].storageUtilized, storageUtilized);
assert.deepStrictEqual(res[0].numberOfObjects, numberOfObjects);
return cb();
});
}

describe('multiple runs', function test() {
this.timeout(30000);

function waitUntilLockHasValue({ value, job }, cb) {
let shouldLeave;
let shouldCallJob = job !== undefined;
const bucket = `${mock.values.BUCKET_NAME}-multi-run`;

beforeEach(() => {
bucketD
.setBucketContent({
bucketName: bucket,
contentLength: 1024,
})
.setBucketContent({
bucketName: MPUBucket,

Check failure on line 235 in tests/functional/cron/testReindex.js

View workflow job for this annotation

GitHub Actions / lint

'MPUBucket' is not defined
contentLength: 1024,
})
.setBucketCount(count)

Check failure on line 238 in tests/functional/cron/testReindex.js

View workflow job for this annotation

GitHub Actions / lint

'count' is not defined
.createBuckets();
});

async.doUntil(next => redis.get(REINDEX_LOCK_KEY, (err, res) => {
if (err) {
return next(err);
}
if (shouldCallJob) {
job();
shouldCallJob = false;
}
shouldLeave = res === value;
return setTimeout(next, 200);
}),
next => next(null, shouldLeave), cb);
}

function checkMetrics({ resource, expected }, cb) {
utils.listMetrics(resource, (err, res) => {
afterEach(() => {
bucketD.clearBuckets();
});

it('should not remove metrics for the previous interval if they have not changed', done => {
function job() {
reindex._scheduleJob();
}

// Wait until the scripts have finished reindexing.
async.series(
[
next => waitUntilLockHasValue({ value: 'true', job }, next),
next => waitUntilLockHasValue({ value: null }, next),
],
done,
);

utils.listMetrics(bucket, (err, res) => {

Check warning on line 260 in tests/functional/cron/testReindex.js

View workflow job for this annotation

GitHub Actions / lint

Expected to return a value at the end of arrow function
if (err) {
return cb(err);
return done(err);
}

if (res.code) {
return cb(new Error(res.message));
return done(new Error(res.message));
}
const { storageUtilized, numberOfObjects } = expected;
assert.deepStrictEqual(res[0].storageUtilized, storageUtilized);
assert.deepStrictEqual(res[0].numberOfObjects, numberOfObjects);
return cb();
const { storageUtilized, numberOfObjects } = res[0];
assert.deepStrictEqual(storageUtilized, [0, 1024]);
assert.deepStrictEqual(numberOfObjects, [0, 1]);

// Run the job again.
job();

// Wait until the scripts have finished reindexing.
async.series(
[
next =>
waitUntilLockHasValue({ value: 'true', job }, next),
next =>
waitUntilLockHasValue({ value: null }, next),
],
done,
);

utils.listMetrics(bucket, (err, res) => {
if (err) {
return done(err);
}
if (res.code) {
return done(new Error(res.message));
}
const { storageUtilized, numberOfObjects } = res[0];
assert.deepStrictEqual(storageUtilized, [0, 1024]);
assert.deepStrictEqual(numberOfObjects, [0, 1]);
return done();
});
});
}
});
});

describe('::_scheduleJob', function test() {
this.timeout(30000);

const bucketCounts = [1, 1001];

Expand Down

0 comments on commit b203f48

Please sign in to comment.