Monitor cache saves and add basic caching report

- Restore `CachingReport` instance in 'post' action
- Record keys for any entries saved
- Report caching activity as JSON in post action
This commit is contained in:
Daz DeBoer 2021-10-29 10:41:30 -06:00
parent 6ff2065a12
commit a74bb0fad6
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
4 changed files with 155 additions and 20 deletions

View file

@ -1,5 +1,4 @@
import * as cacheUtils from '../src/cache-utils'
import * as path from 'path'
describe('cacheUtils-utils', () => {
describe('can hash', () => {
@ -18,4 +17,97 @@ describe('cacheUtils-utils', () => {
expect(posixHash).toBe(windowsHash)
})
})
describe('caching report', () => {
describe('reports not fully restored', () => {
it('with one requested entry report', async () => {
const report = new cacheUtils.CachingReport()
report.entryReport('foo').markRequested('1', ['2'])
report.entryReport('bar').markRequested('3').markRestored('4')
expect(report.fullyRestored).toBe(false)
})
})
describe('reports fully restored', () => {
it('when empty', async () => {
const report = new cacheUtils.CachingReport()
expect(report.fullyRestored).toBe(true)
})
it('with empty entry reports', async () => {
const report = new cacheUtils.CachingReport()
report.entryReport('foo')
report.entryReport('bar')
expect(report.fullyRestored).toBe(true)
})
it('with restored entry report', async () => {
const report = new cacheUtils.CachingReport()
report.entryReport('bar').markRequested('3').markRestored('4')
expect(report.fullyRestored).toBe(true)
})
it('with multiple restored entry reportss', async () => {
const report = new cacheUtils.CachingReport()
report.entryReport('foo').markRestored('4')
report.entryReport('bar').markRequested('3').markRestored('4')
expect(report.fullyRestored).toBe(true)
})
})
describe('can be stringified and rehydrated', () => {
it('when empty', async () => {
const report = new cacheUtils.CachingReport()
const stringRep = report.stringify()
const reportClone: cacheUtils.CachingReport = cacheUtils.CachingReport.rehydrate(stringRep)
expect(reportClone.cacheEntryReports).toEqual([])
// Can call methods on rehydrated
expect(reportClone.entryReport('foo')).toBeInstanceOf(cacheUtils.CacheEntryReport)
})
it('with entry reports', async () => {
const report = new cacheUtils.CachingReport()
report.entryReport('foo')
report.entryReport('bar')
report.entryReport('baz')
const stringRep = report.stringify()
const reportClone: cacheUtils.CachingReport = cacheUtils.CachingReport.rehydrate(stringRep)
expect(reportClone.cacheEntryReports.length).toBe(3)
expect(reportClone.cacheEntryReports[0].entryName).toBe('foo')
expect(reportClone.cacheEntryReports[1].entryName).toBe('bar')
expect(reportClone.cacheEntryReports[2].entryName).toBe('baz')
expect(reportClone.entryReport('foo')).toBe(reportClone.cacheEntryReports[0])
})
it('with rehydrated entry report', async () => {
const report = new cacheUtils.CachingReport()
const entryReport = report.entryReport('foo')
entryReport.markRequested('1', ['2', '3'])
entryReport.markSaved('4')
const stringRep = report.stringify()
const reportClone: cacheUtils.CachingReport = cacheUtils.CachingReport.rehydrate(stringRep)
const entryClone = reportClone.entryReport('foo')
expect(entryClone.requestedKey).toBe('1')
expect(entryClone.requestedRestoreKeys).toEqual(['2', '3'])
expect(entryClone.savedKey).toBe('4')
})
it('with live entry report', async () => {
const report = new cacheUtils.CachingReport()
const entryReport = report.entryReport('foo')
entryReport.markRequested('1', ['2', '3'])
const stringRep = report.stringify()
const reportClone: cacheUtils.CachingReport = cacheUtils.CachingReport.rehydrate(stringRep)
const entryClone = reportClone.entryReport('foo')
// Check type and call method on rehydrated entry report
expect(entryClone).toBeInstanceOf(cacheUtils.CacheEntryReport)
entryClone.markSaved('4')
expect(entryClone.requestedKey).toBe('1')
expect(entryClone.requestedRestoreKeys).toEqual(['2', '3'])
expect(entryClone.savedKey).toBe('4')
})
})
})
})