Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Apr 8, 2024
1 parent 323bd96 commit d8c55bc
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/bentocache/tests/cache/two_tier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,32 @@ test.group('Cache', () => {

test('should throws if graced value is outdated', async ({ assert }) => {
const { cache } = new CacheFactory()
.merge({ gracePeriod: { enabled: true, duration: '100ms' } })
.merge({ gracePeriod: { enabled: true, duration: '400ms' } })
.withL1L2Config()
.create()

// init factory
const r1 = await cache.getOrSet('key1', () => ({ foo: 'bar' }), { ttl: '10ms' })
const r1 = await cache.getOrSet({
key: 'key1',
ttl: '10ms',
factory: () => ({ foo: 'bar' }),
})

// re-get with throwing factory. still in grace period
const r2 = await cache.getOrSet('key1', throwingFactory('should not be called'), {
const r2 = await cache.getOrSet({
key: 'key1',
ttl: '10ms',
factory: throwingFactory('error in factory'),
})
await setTimeout(101)

await setTimeout(500)

// re-get with throwing factory. out of grace period. should throws
const r3 = cache.getOrSet('key1', throwingFactory('error in factory'), { ttl: '10ms' })
const r3 = cache.getOrSet({
key: 'key1',
ttl: '10ms',
factory: throwingFactory('error in factory'),
})

assert.deepEqual(r1, { foo: 'bar' })
assert.deepEqual(r2, { foo: 'bar' })
Expand Down Expand Up @@ -381,7 +392,7 @@ test.group('Cache', () => {

test('early refresh should re-increment physical/logical ttls', async ({ assert }) => {
const { cache } = new CacheFactory()
.merge({ earlyExpiration: 0.5, ttl: 100 })
.merge({ earlyExpiration: 0.5, ttl: '500ms' })
.withL1L2Config()
.create()

Expand Down

0 comments on commit d8c55bc

Please sign in to comment.