1
0
Fork 0
pull/1122/head
Shubham Tiwari 2022-06-20 04:54:54 +00:00 committed by GitHub
parent 639c79e4a4
commit 8c47ec23fe
3 changed files with 41 additions and 29 deletions

View File

@ -73,7 +73,7 @@ test('restore with no cache found', async () => {
test('restore with server error should fail', async () => { test('restore with server error should fail', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const key = 'node-test' const key = 'node-test'
const logWarningMock = jest.spyOn(core, "warning"); const logWarningMock = jest.spyOn(core, 'warning')
jest.spyOn(cacheHttpClient, 'getCacheEntry').mockImplementation(() => { jest.spyOn(cacheHttpClient, 'getCacheEntry').mockImplementation(() => {
throw new Error('HTTP Error Occurred') throw new Error('HTTP Error Occurred')
@ -82,7 +82,9 @@ test('restore with server error should fail', async () => {
const cacheKey = await restoreCache(paths, key) const cacheKey = await restoreCache(paths, key)
expect(cacheKey).toBe(undefined) expect(cacheKey).toBe(undefined)
expect(logWarningMock).toHaveBeenCalledTimes(1) expect(logWarningMock).toHaveBeenCalledTimes(1)
expect(logWarningMock).toHaveBeenCalledWith('Fail to restore: Error: HTTP Error Occurred') expect(logWarningMock).toHaveBeenCalledWith(
'Fail to restore: Error: HTTP Error Occurred'
)
}) })
test('restore with restore keys and no cache found', async () => { test('restore with restore keys and no cache found', async () => {

View File

@ -48,7 +48,7 @@ test('save with large cache outputs should fail', async () => {
const cachePaths = [path.resolve(filePath)] const cachePaths = [path.resolve(filePath)]
const createTarMock = jest.spyOn(tar, 'createTar') const createTarMock = jest.spyOn(tar, 'createTar')
const logWarningMock = jest.spyOn(core, "warning"); const logWarningMock = jest.spyOn(core, 'warning')
const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit
jest jest
@ -62,7 +62,9 @@ test('save with large cache outputs should fail', async () => {
const cacheId = await saveCache([filePath], primaryKey) const cacheId = await saveCache([filePath], primaryKey)
expect(cacheId).toBe(-1) expect(cacheId).toBe(-1)
expect(logWarningMock).toHaveBeenCalledTimes(1) expect(logWarningMock).toHaveBeenCalledTimes(1)
expect(logWarningMock).toHaveBeenCalledWith('Fail to save: Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.') expect(logWarningMock).toHaveBeenCalledWith(
'Fail to save: Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.'
)
const archiveFolder = '/foo/bar' const archiveFolder = '/foo/bar'
@ -81,7 +83,7 @@ test('save with large cache outputs should fail in GHES with error message', asy
const cachePaths = [path.resolve(filePath)] const cachePaths = [path.resolve(filePath)]
const createTarMock = jest.spyOn(tar, 'createTar') const createTarMock = jest.spyOn(tar, 'createTar')
const logWarningMock = jest.spyOn(core, "warning"); const logWarningMock = jest.spyOn(core, 'warning')
const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit
jest jest
@ -112,7 +114,9 @@ test('save with large cache outputs should fail in GHES with error message', asy
const cacheId = await saveCache([filePath], primaryKey) const cacheId = await saveCache([filePath], primaryKey)
expect(cacheId).toBe(-1) expect(cacheId).toBe(-1)
expect(logWarningMock).toHaveBeenCalledTimes(1) expect(logWarningMock).toHaveBeenCalledTimes(1)
expect(logWarningMock).toHaveBeenCalledWith('Fail to save: The cache filesize must be between 0 and 1073741824 bytes') expect(logWarningMock).toHaveBeenCalledWith(
'Fail to save: The cache filesize must be between 0 and 1073741824 bytes'
)
const archiveFolder = '/foo/bar' const archiveFolder = '/foo/bar'
expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledTimes(1)
@ -131,7 +135,7 @@ test('save with large cache outputs should fail in GHES without error message',
const cachePaths = [path.resolve(filePath)] const cachePaths = [path.resolve(filePath)]
const createTarMock = jest.spyOn(tar, 'createTar') const createTarMock = jest.spyOn(tar, 'createTar')
const logWarningMock = jest.spyOn(core, "warning"); const logWarningMock = jest.spyOn(core, 'warning')
const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit const cacheSize = 11 * 1024 * 1024 * 1024 //~11GB, over the 10GB limit
jest jest
@ -158,7 +162,9 @@ test('save with large cache outputs should fail in GHES without error message',
const cacheId = await saveCache([filePath], primaryKey) const cacheId = await saveCache([filePath], primaryKey)
expect(cacheId).toBe(-1) expect(cacheId).toBe(-1)
expect(logWarningMock).toHaveBeenCalledTimes(1) expect(logWarningMock).toHaveBeenCalledTimes(1)
expect(logWarningMock).toHaveBeenCalledWith('Fail to save: Cache size of ~11264 MB (11811160064 B) is over the data cap limit, not saving cache.') expect(logWarningMock).toHaveBeenCalledWith(
'Fail to save: Cache size of ~11264 MB (11811160064 B) is over the data cap limit, not saving cache.'
)
const archiveFolder = '/foo/bar' const archiveFolder = '/foo/bar'
expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledTimes(1)
@ -174,7 +180,7 @@ test('save with large cache outputs should fail in GHES without error message',
test('save with reserve cache failure should fail', async () => { test('save with reserve cache failure should fail', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43' const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
const logInfoMock = jest.spyOn(core, "info"); const logInfoMock = jest.spyOn(core, 'info')
const reserveCacheMock = jest const reserveCacheMock = jest
.spyOn(cacheHttpClient, 'reserveCache') .spyOn(cacheHttpClient, 'reserveCache')
@ -197,7 +203,9 @@ test('save with reserve cache failure should fail', async () => {
const cacheId = await saveCache(paths, primaryKey) const cacheId = await saveCache(paths, primaryKey)
expect(cacheId).toBe(-1) expect(cacheId).toBe(-1)
expect(logInfoMock).toHaveBeenCalledTimes(1) expect(logInfoMock).toHaveBeenCalledTimes(1)
expect(logInfoMock).toHaveBeenCalledWith(`Fail to save: Unable to reserve cache with key ${primaryKey}, another job may be creating this cache. More details: undefined`) expect(logInfoMock).toHaveBeenCalledWith(
`Fail to save: Unable to reserve cache with key ${primaryKey}, another job may be creating this cache. More details: undefined`
)
expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledTimes(1)
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, { expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, paths, {
@ -212,7 +220,7 @@ test('save with server error should fail', async () => {
const filePath = 'node_modules' const filePath = 'node_modules'
const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43' const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
const cachePaths = [path.resolve(filePath)] const cachePaths = [path.resolve(filePath)]
const logWarningMock = jest.spyOn(core, "warning"); const logWarningMock = jest.spyOn(core, 'warning')
const cacheId = 4 const cacheId = 4
const reserveCacheMock = jest const reserveCacheMock = jest
.spyOn(cacheHttpClient, 'reserveCache') .spyOn(cacheHttpClient, 'reserveCache')
@ -239,7 +247,9 @@ test('save with server error should fail', async () => {
await saveCache([filePath], primaryKey) await saveCache([filePath], primaryKey)
expect(logWarningMock).toHaveBeenCalledTimes(1) expect(logWarningMock).toHaveBeenCalledTimes(1)
expect(logWarningMock).toHaveBeenCalledWith('Fail to save: HTTP Error Occurred') expect(logWarningMock).toHaveBeenCalledWith(
'Fail to save: HTTP Error Occurred'
)
expect(reserveCacheMock).toHaveBeenCalledTimes(1) expect(reserveCacheMock).toHaveBeenCalledTimes(1)
expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], { expect(reserveCacheMock).toHaveBeenCalledWith(primaryKey, [filePath], {

View File

@ -87,7 +87,7 @@ export async function restoreCache(
} }
const compressionMethod = await utils.getCompressionMethod() const compressionMethod = await utils.getCompressionMethod()
let archivePath = "" let archivePath = ''
try { try {
// path are needed to compute version // path are needed to compute version
const cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, { const cacheEntry = await cacheHttpClient.getCacheEntry(keys, paths, {
@ -129,7 +129,7 @@ export async function restoreCache(
return cacheEntry.cacheKey return cacheEntry.cacheKey
} catch (error) { } catch (error) {
// Supress all cache related errors because caching should be optional // Supress all cache related errors because caching should be optional
core.warning(`Fail to restore: ${error}`); core.warning(`Fail to restore: ${error}`)
} finally { } finally {
// Try to delete the archive to save space // Try to delete the archive to save space
try { try {
@ -225,7 +225,7 @@ export async function saveCache(
core.debug(`Saving Cache (ID: ${cacheId})`) core.debug(`Saving Cache (ID: ${cacheId})`)
await cacheHttpClient.saveCache(cacheId, archivePath, options) await cacheHttpClient.saveCache(cacheId, archivePath, options)
} catch (error) { } catch (error) {
const typedError = error as Error; const typedError = error as Error
if (typedError.name === ReserveCacheError.name) { if (typedError.name === ReserveCacheError.name) {
core.info(`Fail to save: ${typedError.message}`) core.info(`Fail to save: ${typedError.message}`)
} else { } else {