Expose control of the number of open files in libvips' cache.

Breaks API of existing cache method.
Disable libvips cache for I/O tests.
This commit is contained in:
Lovell Fuller
2016-01-06 20:37:37 +00:00
parent 8843211e12
commit 11329d5e09
29 changed files with 126 additions and 82 deletions

View File

@@ -4,8 +4,6 @@ var assert = require('assert');
var fixtures = require('../fixtures');
var sharp = require('../../index');
sharp.cache(0);
describe('Alpha transparency', function() {
it('Flatten to black', function(done) {

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Blur', function() {
it('specific radius 1', function(done) {

View File

@@ -6,9 +6,15 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Clone', function() {
before(function() {
sharp.cache(false);
});
after(function() {
sharp.cache(true);
});
it('Read from Stream and write to multiple Streams', function(done) {
var finishEventsExpected = 2;
// Output stream 1
@@ -55,4 +61,5 @@ describe('Clone', function() {
// Go
fs.createReadStream(fixtures.inputJpg).pipe(rotator);
});
});

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Colour space conversion', function() {
it('To greyscale', function(done) {

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Crop gravities', function() {
var testSettings = [

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Embed', function() {
it('JPEG within PNG, no alpha channel', function(done) {

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Partial image extraction', function() {
describe('using the legacy extract(top,left,width,height) syntax', function () {
it('JPEG', function(done) {

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Gamma correction', function() {
it('value of 0.0 (disabled)', function(done) {

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Interpolation', function() {
it('nearest neighbour', function(done) {

View File

@@ -6,10 +6,15 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Input/output', function() {
before(function() {
sharp.cache(false);
});
after(function() {
sharp.cache(true);
});
it('Read from File and write to Stream', function(done) {
var writable = fs.createWriteStream(fixtures.outputJpg);
writable.on('finish', function() {

View File

@@ -8,8 +8,6 @@ var icc = require('icc');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Image metadata', function() {
it('JPEG', function(done) {

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Negate', function() {
it('negate (jpeg)', function(done) {
sharp(fixtures.inputJpg)

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Normalization', function () {
it('uses the same prototype for both spellings', function () {

View File

@@ -4,8 +4,6 @@ var assert = require('assert');
var fixtures = require('../fixtures');
var sharp = require('../../index');
sharp.cache(0);
// Helpers
var getPaths = function(baseName, extension) {
if (typeof extension === 'undefined') {

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Resize dimensions', function() {
it('Exact crop', function(done) {

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Rotation', function() {
['Landscape', 'Portrait'].forEach(function(orientation) {

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Sharpen', function() {
it('specific radius 10', function(done) {

View File

@@ -5,8 +5,6 @@ var assert = require('assert');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
describe('Threshold', function() {
it('threshold 1 jpeg', function(done) {
sharp(fixtures.inputJpg)

View File

@@ -10,8 +10,6 @@ var rimraf = require('rimraf');
var sharp = require('../../index');
var fixtures = require('../fixtures');
sharp.cache(0);
// Verifies all tiles in a given dz output directory are <= size
var assertDeepZoomTiles = function(directory, expectedSize, expectedLevels, done) {
// Get levels

View File

@@ -10,20 +10,48 @@ describe('Utilities', function() {
describe('Cache', function() {
it('Can be disabled', function() {
var cache = sharp.cache(0, 0);
assert.strictEqual(0, cache.memory);
assert.strictEqual(0, cache.items);
sharp.cache(false);
var cache = sharp.cache(false);
assert.strictEqual(cache.memory.current, 0);
assert.strictEqual(cache.memory.max, 0);
assert.strictEqual(typeof cache.memory.high, 'number');
assert.strictEqual(cache.files.current, 0);
assert.strictEqual(cache.files.max, 0);
assert.strictEqual(cache.items.current, 0);
assert.strictEqual(cache.items.max, 0);
});
it('Can be set to a maximum of 50MB and 500 items', function() {
var cache = sharp.cache(50, 500);
assert.strictEqual(50, cache.memory);
assert.strictEqual(500, cache.items);
it('Can be enabled with defaults', function() {
var cache = sharp.cache(true);
assert.strictEqual(cache.memory.max, 50);
assert.strictEqual(cache.files.max, 20);
assert.strictEqual(cache.items.max, 100);
});
it('Can be set to zero', function() {
var cache = sharp.cache({
memory: 0,
files: 0,
items: 0
});
assert.strictEqual(cache.memory.max, 0);
assert.strictEqual(cache.files.max, 0);
assert.strictEqual(cache.items.max, 0);
});
it('Can be set to a maximum of 10MB, 100 files and 1000 items', function() {
var cache = sharp.cache({
memory: 10,
files: 100,
items: 1000
});
assert.strictEqual(cache.memory.max, 10);
assert.strictEqual(cache.files.max, 100);
assert.strictEqual(cache.items.max, 1000);
});
it('Ignores invalid values', function() {
sharp.cache(50, 500);
sharp.cache(true);
var cache = sharp.cache('spoons');
assert.strictEqual(50, cache.memory);
assert.strictEqual(500, cache.items);
assert.strictEqual(cache.memory.max, 50);
assert.strictEqual(cache.files.max, 20);
assert.strictEqual(cache.items.max, 100);
});
});