Skip to content

Commit

Permalink
Revising filesystem tests for consecutiveErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewshell committed Apr 5, 2023
1 parent f2aaf1b commit 67e57a0
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 79 deletions.
163 changes: 85 additions & 78 deletions test/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,21 @@ describe('filesystem', function() {
});

it('should return a Miss on error', async function () {
const c = await cache.go('-internal', 'cache', Cacheism.Status.onlyFresh, async () => {
throw Error('cache error');
});
let c, d, e;
for (e = 1; e < 3; e++) {
c = await cache.go('-internal', 'cache', Cacheism.Status.onlyFresh, async () => {
throw Error('cache error');
});

helpers.expectCacheMiss(c, false, null);
helpers.expectCacheErrors(c, 'cache error', 1);
expect(c.created).to.eql(c.errorTime);
helpers.expectCacheMiss(c, false, null);
helpers.expectCacheErrors(c, 'Error: cache error', e);

expect(await cache.store.isset('-internal/cache')).to.be(true);
const d = await cache.store.get('-internal/cache');
expect(await cache.store.isset('-internal/cache')).to.be(true);
d = await cache.store.get('-internal/cache');

helpers.expectDataMiss(d, null);
helpers.expectDataErrors(d, 'Error: cache error', 1);
expect(d.created).to.eql(d.errorTime);
helpers.expectDataMiss(d, null);
helpers.expectDataErrors(d, 'Error: cache error', e);
}
});

});
Expand Down Expand Up @@ -102,20 +103,21 @@ describe('filesystem', function() {

mockdate.reset();

const c = await cache.go('-internal', 'cache', Cacheism.Status.onlyFresh, async () => {
throw Error('cache error');
});
let c, d, e;
for (e = 1; e < 3; e++) {
c = await cache.go('-internal', 'cache', Cacheism.Status.onlyFresh, async () => {
throw Error('cache error');
});

helpers.expectCacheMiss(c, false, null);
helpers.expectCacheErrors(c, 'cache error', 1);
expect(c.created).to.eql(c.errorTime);
helpers.expectCacheMiss(c, false, null);
helpers.expectCacheErrors(c, 'Error: cache error', e);

expect(await cache.store.isset('-internal/cache')).to.be(true);
const d = await cache.store.get('-internal/cache');
expect(await cache.store.isset('-internal/cache')).to.be(true);
d = await cache.store.get('-internal/cache');

helpers.expectDataMiss(d, null);
helpers.expectDataErrors(d, 'Error: cache error', 1);
expect(d.created).to.eql(d.errorTime);
helpers.expectDataMiss(d, null);
helpers.expectDataErrors(d, 'Error: cache error', e);
}
});

});
Expand All @@ -142,20 +144,21 @@ describe('filesystem', function() {
});

it('should return a Miss on error', async function () {
const c = await cache.go('-internal', 'cache', Cacheism.Status.cacheOnFail, async () => {
throw Error('cache error');
});
let c, d, e;
for (e = 1; e < 3; e++) {
c = await cache.go('-internal', 'cache', Cacheism.Status.cacheOnFail, async () => {
throw Error('cache error');
});

helpers.expectCacheMiss(c, false, null);
helpers.expectCacheErrors(c, 'cache error', 1);
expect(c.created).to.eql(c.errorTime);
helpers.expectCacheMiss(c, false, null);
helpers.expectCacheErrors(c, 'Error: cache error', e);

expect(await cache.store.isset('-internal/cache')).to.be(true);
const d = await cache.store.get('-internal/cache');
expect(await cache.store.isset('-internal/cache')).to.be(true);
d = await cache.store.get('-internal/cache');

helpers.expectDataMiss(d, null, c.etag);
helpers.expectDataErrors(d, 'Error: cache error', 1);
expect(d.created).to.eql(d.errorTime);
helpers.expectDataMiss(d, null, c.etag);
helpers.expectDataErrors(d, 'Error: cache error', e);
}
});

});
Expand Down Expand Up @@ -194,20 +197,21 @@ describe('filesystem', function() {

mockdate.reset();

const c = await cache.go('-internal', 'cache', Cacheism.Status.cacheOnFail, async () => {
throw Error('cache error');
});
let c, d, e;
for (e = 1; e < 3; e++) {
c = await cache.go('-internal', 'cache', Cacheism.Status.cacheOnFail, async () => {
throw Error('cache error');
});

helpers.expectCacheHit(c, true, 'cached');
helpers.expectCacheErrors(c, 'cache error', 1);
expect(c.created).not.to.eql(c.errorTime);
helpers.expectCacheHit(c, true, 'cached');
helpers.expectCacheErrors(c, 'Error: cache error', e);

expect(await cache.store.isset('-internal/cache')).to.be(true);
const d = await cache.store.get('-internal/cache');
expect(await cache.store.isset('-internal/cache')).to.be(true);
d = await cache.store.get('-internal/cache');

helpers.expectDataHit(d, 'cached', c.etag);
helpers.expectDataErrors(d, 'Error: cache error', 1);
expect(d.created).not.to.eql(d.errorTime);
helpers.expectDataHit(d, 'cached', c.etag);
helpers.expectDataErrors(d, 'Error: cache error', e);
}
});

});
Expand All @@ -234,20 +238,21 @@ describe('filesystem', function() {
});

it('should return a Miss on error', async function () {
const c = await cache.go('-internal', 'cache', Cacheism.Status.preferCache, async () => {
throw Error('cache error');
});
let c, d, e;
for (e = 1; e < 3; e++) {
c = await cache.go('-internal', 'cache', Cacheism.Status.preferCache, async () => {
throw Error('cache error');
});

helpers.expectCacheMiss(c, false, null);
helpers.expectCacheErrors(c, 'cache error', 1);
expect(c.created).to.eql(c.errorTime);
helpers.expectCacheMiss(c, false, null);
helpers.expectCacheErrors(c, 'Error: cache error', e);

expect(await cache.store.isset('-internal/cache')).to.be(true);
const d = await cache.store.get('-internal/cache');
expect(await cache.store.isset('-internal/cache')).to.be(true);
d = await cache.store.get('-internal/cache');

helpers.expectDataMiss(d, null, c.etag);
helpers.expectDataErrors(d, 'Error: cache error', 1);
expect(d.created).to.eql(d.errorTime);
helpers.expectDataMiss(d, null, c.etag);
helpers.expectDataErrors(d, 'Error: cache error', e);
}
});

});
Expand Down Expand Up @@ -286,18 +291,21 @@ describe('filesystem', function() {

mockdate.reset();

const c = await cache.go('-internal', 'cache', Cacheism.Status.preferCache, async () => {
throw Error('cache error');
});
let c, d, e;
for (e = 1; e < 3; e++) {
c = await cache.go('-internal', 'cache', Cacheism.Status.preferCache, async () => {
throw Error('cache error');
});

helpers.expectCacheHit(c, true, 'cached');
helpers.expectCacheNoErrors(c);
helpers.expectCacheHit(c, true, 'cached');
helpers.expectCacheNoErrors(c);

expect(await cache.store.isset('-internal/cache')).to.be(true);
const d = await cache.store.get('-internal/cache');
expect(await cache.store.isset('-internal/cache')).to.be(true);
d = await cache.store.get('-internal/cache');

helpers.expectDataHit(d, 'cached', c.etag);
helpers.expectDataNoErrors(d);
helpers.expectDataHit(d, 'cached', c.etag);
helpers.expectDataNoErrors(d);
}
});

});
Expand All @@ -314,32 +322,31 @@ describe('filesystem', function() {
});

helpers.expectCacheMiss(c, false, null);
helpers.expectCacheErrors(c, 'Missing cache', 1);
expect(c.created).to.eql(c.errorTime);
helpers.expectCacheErrors(c, 'Error: Missing cache', 1);

expect(await cache.store.isset('-internal/cache')).to.be(true);
const d = await cache.store.get('-internal/cache');

helpers.expectDataMiss(d, null, null);
helpers.expectDataErrors(d, 'Error: Missing cache', 1);
expect(d.created).to.eql(d.errorTime);
});

it('should return a Miss on error', async function () {
const c = await cache.go('-internal', 'cache', Cacheism.Status.onlyCache, async () => {
throw Error('cache error');
});
let c, d, e;
for (e = 1; e < 3; e++) {
c = await cache.go('-internal', 'cache', Cacheism.Status.onlyCache, async () => {
throw Error('cache error');
});

helpers.expectCacheMiss(c, false, null);
helpers.expectCacheErrors(c, 'Missing cache', 1);
expect(c.created).to.eql(c.errorTime);
helpers.expectCacheMiss(c, false, null);
helpers.expectCacheErrors(c, 'Error: Missing cache', e);

expect(await cache.store.isset('-internal/cache')).to.be(true);
const d = await cache.store.get('-internal/cache');
expect(await cache.store.isset('-internal/cache')).to.be(true);
d = await cache.store.get('-internal/cache');

helpers.expectDataMiss(d, null, null);
helpers.expectDataErrors(d, 'Error: Missing cache', 1);
expect(d.created).to.eql(d.errorTime);
helpers.expectDataMiss(d, null, null);
helpers.expectDataErrors(d, 'Error: Missing cache', e);
}
});

});
Expand Down
2 changes: 1 addition & 1 deletion test/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const cache = new Cacheism(Cacheism.store.memory());

const helpers = require('./helpers');

describe.only('memory', function() {
describe('memory', function() {

beforeEach(function() {
// runs before each test in this block
Expand Down

0 comments on commit 67e57a0

Please sign in to comment.