Skip to content

Commit 67e57a0

Browse files
committed
Revising filesystem tests for consecutiveErrors
1 parent f2aaf1b commit 67e57a0

File tree

2 files changed

+86
-79
lines changed

2 files changed

+86
-79
lines changed

test/filesystem.js

Lines changed: 85 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@ describe('filesystem', function() {
5050
});
5151

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

57-
helpers.expectCacheMiss(c, false, null);
58-
helpers.expectCacheErrors(c, 'cache error', 1);
59-
expect(c.created).to.eql(c.errorTime);
59+
helpers.expectCacheMiss(c, false, null);
60+
helpers.expectCacheErrors(c, 'Error: cache error', e);
6061

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

64-
helpers.expectDataMiss(d, null);
65-
helpers.expectDataErrors(d, 'Error: cache error', 1);
66-
expect(d.created).to.eql(d.errorTime);
65+
helpers.expectDataMiss(d, null);
66+
helpers.expectDataErrors(d, 'Error: cache error', e);
67+
}
6768
});
6869

6970
});
@@ -102,20 +103,21 @@ describe('filesystem', function() {
102103

103104
mockdate.reset();
104105

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

109-
helpers.expectCacheMiss(c, false, null);
110-
helpers.expectCacheErrors(c, 'cache error', 1);
111-
expect(c.created).to.eql(c.errorTime);
112+
helpers.expectCacheMiss(c, false, null);
113+
helpers.expectCacheErrors(c, 'Error: cache error', e);
112114

113-
expect(await cache.store.isset('-internal/cache')).to.be(true);
114-
const d = await cache.store.get('-internal/cache');
115+
expect(await cache.store.isset('-internal/cache')).to.be(true);
116+
d = await cache.store.get('-internal/cache');
115117

116-
helpers.expectDataMiss(d, null);
117-
helpers.expectDataErrors(d, 'Error: cache error', 1);
118-
expect(d.created).to.eql(d.errorTime);
118+
helpers.expectDataMiss(d, null);
119+
helpers.expectDataErrors(d, 'Error: cache error', e);
120+
}
119121
});
120122

121123
});
@@ -142,20 +144,21 @@ describe('filesystem', function() {
142144
});
143145

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

149-
helpers.expectCacheMiss(c, false, null);
150-
helpers.expectCacheErrors(c, 'cache error', 1);
151-
expect(c.created).to.eql(c.errorTime);
153+
helpers.expectCacheMiss(c, false, null);
154+
helpers.expectCacheErrors(c, 'Error: cache error', e);
152155

153-
expect(await cache.store.isset('-internal/cache')).to.be(true);
154-
const d = await cache.store.get('-internal/cache');
156+
expect(await cache.store.isset('-internal/cache')).to.be(true);
157+
d = await cache.store.get('-internal/cache');
155158

156-
helpers.expectDataMiss(d, null, c.etag);
157-
helpers.expectDataErrors(d, 'Error: cache error', 1);
158-
expect(d.created).to.eql(d.errorTime);
159+
helpers.expectDataMiss(d, null, c.etag);
160+
helpers.expectDataErrors(d, 'Error: cache error', e);
161+
}
159162
});
160163

161164
});
@@ -194,20 +197,21 @@ describe('filesystem', function() {
194197

195198
mockdate.reset();
196199

197-
const c = await cache.go('-internal', 'cache', Cacheism.Status.cacheOnFail, async () => {
198-
throw Error('cache error');
199-
});
200+
let c, d, e;
201+
for (e = 1; e < 3; e++) {
202+
c = await cache.go('-internal', 'cache', Cacheism.Status.cacheOnFail, async () => {
203+
throw Error('cache error');
204+
});
200205

201-
helpers.expectCacheHit(c, true, 'cached');
202-
helpers.expectCacheErrors(c, 'cache error', 1);
203-
expect(c.created).not.to.eql(c.errorTime);
206+
helpers.expectCacheHit(c, true, 'cached');
207+
helpers.expectCacheErrors(c, 'Error: cache error', e);
204208

205-
expect(await cache.store.isset('-internal/cache')).to.be(true);
206-
const d = await cache.store.get('-internal/cache');
209+
expect(await cache.store.isset('-internal/cache')).to.be(true);
210+
d = await cache.store.get('-internal/cache');
207211

208-
helpers.expectDataHit(d, 'cached', c.etag);
209-
helpers.expectDataErrors(d, 'Error: cache error', 1);
210-
expect(d.created).not.to.eql(d.errorTime);
212+
helpers.expectDataHit(d, 'cached', c.etag);
213+
helpers.expectDataErrors(d, 'Error: cache error', e);
214+
}
211215
});
212216

213217
});
@@ -234,20 +238,21 @@ describe('filesystem', function() {
234238
});
235239

236240
it('should return a Miss on error', async function () {
237-
const c = await cache.go('-internal', 'cache', Cacheism.Status.preferCache, async () => {
238-
throw Error('cache error');
239-
});
241+
let c, d, e;
242+
for (e = 1; e < 3; e++) {
243+
c = await cache.go('-internal', 'cache', Cacheism.Status.preferCache, async () => {
244+
throw Error('cache error');
245+
});
240246

241-
helpers.expectCacheMiss(c, false, null);
242-
helpers.expectCacheErrors(c, 'cache error', 1);
243-
expect(c.created).to.eql(c.errorTime);
247+
helpers.expectCacheMiss(c, false, null);
248+
helpers.expectCacheErrors(c, 'Error: cache error', e);
244249

245-
expect(await cache.store.isset('-internal/cache')).to.be(true);
246-
const d = await cache.store.get('-internal/cache');
250+
expect(await cache.store.isset('-internal/cache')).to.be(true);
251+
d = await cache.store.get('-internal/cache');
247252

248-
helpers.expectDataMiss(d, null, c.etag);
249-
helpers.expectDataErrors(d, 'Error: cache error', 1);
250-
expect(d.created).to.eql(d.errorTime);
253+
helpers.expectDataMiss(d, null, c.etag);
254+
helpers.expectDataErrors(d, 'Error: cache error', e);
255+
}
251256
});
252257

253258
});
@@ -286,18 +291,21 @@ describe('filesystem', function() {
286291

287292
mockdate.reset();
288293

289-
const c = await cache.go('-internal', 'cache', Cacheism.Status.preferCache, async () => {
290-
throw Error('cache error');
291-
});
294+
let c, d, e;
295+
for (e = 1; e < 3; e++) {
296+
c = await cache.go('-internal', 'cache', Cacheism.Status.preferCache, async () => {
297+
throw Error('cache error');
298+
});
292299

293-
helpers.expectCacheHit(c, true, 'cached');
294-
helpers.expectCacheNoErrors(c);
300+
helpers.expectCacheHit(c, true, 'cached');
301+
helpers.expectCacheNoErrors(c);
295302

296-
expect(await cache.store.isset('-internal/cache')).to.be(true);
297-
const d = await cache.store.get('-internal/cache');
303+
expect(await cache.store.isset('-internal/cache')).to.be(true);
304+
d = await cache.store.get('-internal/cache');
298305

299-
helpers.expectDataHit(d, 'cached', c.etag);
300-
helpers.expectDataNoErrors(d);
306+
helpers.expectDataHit(d, 'cached', c.etag);
307+
helpers.expectDataNoErrors(d);
308+
}
301309
});
302310

303311
});
@@ -314,32 +322,31 @@ describe('filesystem', function() {
314322
});
315323

316324
helpers.expectCacheMiss(c, false, null);
317-
helpers.expectCacheErrors(c, 'Missing cache', 1);
318-
expect(c.created).to.eql(c.errorTime);
325+
helpers.expectCacheErrors(c, 'Error: Missing cache', 1);
319326

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

323330
helpers.expectDataMiss(d, null, null);
324331
helpers.expectDataErrors(d, 'Error: Missing cache', 1);
325-
expect(d.created).to.eql(d.errorTime);
326332
});
327333

328334
it('should return a Miss on error', async function () {
329-
const c = await cache.go('-internal', 'cache', Cacheism.Status.onlyCache, async () => {
330-
throw Error('cache error');
331-
});
335+
let c, d, e;
336+
for (e = 1; e < 3; e++) {
337+
c = await cache.go('-internal', 'cache', Cacheism.Status.onlyCache, async () => {
338+
throw Error('cache error');
339+
});
332340

333-
helpers.expectCacheMiss(c, false, null);
334-
helpers.expectCacheErrors(c, 'Missing cache', 1);
335-
expect(c.created).to.eql(c.errorTime);
341+
helpers.expectCacheMiss(c, false, null);
342+
helpers.expectCacheErrors(c, 'Error: Missing cache', e);
336343

337-
expect(await cache.store.isset('-internal/cache')).to.be(true);
338-
const d = await cache.store.get('-internal/cache');
344+
expect(await cache.store.isset('-internal/cache')).to.be(true);
345+
d = await cache.store.get('-internal/cache');
339346

340-
helpers.expectDataMiss(d, null, null);
341-
helpers.expectDataErrors(d, 'Error: Missing cache', 1);
342-
expect(d.created).to.eql(d.errorTime);
347+
helpers.expectDataMiss(d, null, null);
348+
helpers.expectDataErrors(d, 'Error: Missing cache', e);
349+
}
343350
});
344351

345352
});

test/memory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const cache = new Cacheism(Cacheism.store.memory());
66

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

9-
describe.only('memory', function() {
9+
describe('memory', function() {
1010

1111
beforeEach(function() {
1212
// runs before each test in this block

0 commit comments

Comments
 (0)