Tests: remove a possible race condition

This commit is contained in:
Lovell Fuller 2025-05-19 23:21:55 +01:00
parent c4d6aec48c
commit 63b0a11b5b
2 changed files with 14 additions and 12 deletions

View File

@ -179,7 +179,7 @@
"icc": "^3.0.0", "icc": "^3.0.0",
"jsdoc-to-markdown": "^9.1.1", "jsdoc-to-markdown": "^9.1.1",
"license-checker": "^25.0.1", "license-checker": "^25.0.1",
"mocha": "^11.2.2", "mocha": "^11.4.0",
"node-addon-api": "^8.3.1", "node-addon-api": "^8.3.1",
"nyc": "^17.1.0", "nyc": "^17.1.0",
"prebuild": "^13.0.1", "prebuild": "^13.0.1",

View File

@ -10,18 +10,20 @@ const sharp = require('../../');
describe('Utilities', function () { describe('Utilities', function () {
describe('Cache', function () { describe('Cache', function () {
it('Can be disabled', function (done) { it('Can be disabled', function (done) {
queueMicrotask(() => { const check = setInterval(() => {
sharp.cache(false);
const cache = sharp.cache(false); const cache = sharp.cache(false);
assert.strictEqual(cache.memory.current, 0); const empty =
assert.strictEqual(cache.memory.max, 0); cache.memory.current +
assert.strictEqual(typeof cache.memory.high, 'number'); cache.memory.max +
assert.strictEqual(cache.files.current, 0); cache.files.current +
assert.strictEqual(cache.files.max, 0); cache.files.max +
assert.strictEqual(cache.items.current, 0); cache.items.current +
assert.strictEqual(cache.items.max, 0); cache.items.max === 0;
done(); if (empty) {
}); clearInterval(check);
done();
}
}, 2000);
}); });
it('Can be enabled with defaults', function () { it('Can be enabled with defaults', function () {
const cache = sharp.cache(true); const cache = sharp.cache(true);