From db1d01308c2999654e70c419d5a545c345ed5fa2 Mon Sep 17 00:00:00 2001 From: Bassem Dghaidi <568794+Link-@users.noreply.github.com> Date: Mon, 2 Dec 2024 03:35:20 -0800 Subject: [PATCH] Troubleshoot --- packages/cache/__tests__/uploadUtils.test.ts | 26 +++++++++++- packages/cache/src/cache.ts | 1 + packages/cache/src/internal/uploadUtils.ts | 43 +++++++++++--------- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/packages/cache/__tests__/uploadUtils.test.ts b/packages/cache/__tests__/uploadUtils.test.ts index 6a4876d1..65fed6f7 100644 --- a/packages/cache/__tests__/uploadUtils.test.ts +++ b/packages/cache/__tests__/uploadUtils.test.ts @@ -1,8 +1,8 @@ -import {UploadProgress} from '../src/internal/uploadUtils' +import * as uploadUtils from '../src/internal/uploadUtils' import {TransferProgressEvent} from '@azure/ms-rest-js' test('upload progress tracked correctly', () => { - const progress = new UploadProgress(1000) + const progress = new uploadUtils.UploadProgress(1000) expect(progress.contentLength).toBe(1000) expect(progress.sentBytes).toBe(0) @@ -56,3 +56,25 @@ test('upload progress tracked correctly', () => { expect(progress.getTransferredBytes()).toBe(1000) expect(progress.isDone()).toBe(true) }) + +// test('upload to azure blob storage is successful', () => { +// const archivePath = 'path/to/archive.tzst' +// const signedUploadURL = 'https://storage10.blob.core.windows.net/cache-container/3fe-60?se=2024-12-002T11%3A08%3A58Z&sv=2024-11-04' +// const options: UploadOptions = { +// useAzureSdk: true, +// uploadChunkSize: 64 * 1024 * 1024, +// uploadConcurrency: 8 +// } + +// jest.spyOn(uploadUtils.UploadProgress.prototype, 'onProgress').mockImplementation(() => (progress: TransferProgressEvent) => { +// return progress.loadedBytes +// }) + +// jest.spyOn(uploadUtils.UploadProgress.prototype, 'onProgress').mockImplementation(() => (progress: TransferProgressEvent) => { +// return progress.loadedBytes +// }) + +// const response = uploadUtils.uploadCacheArchiveSDK(signedUploadURL, archivePath, options) + +// expect(response).toBeInstanceOf(Promise) +// }) diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index 2a89d50d..69931e29 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -561,6 +561,7 @@ async function saveCacheV2( } else { core.warning(`Failed to save: ${typedError.message}`) } + throw error } finally { // Try to delete the archive to save space try { diff --git a/packages/cache/src/internal/uploadUtils.ts b/packages/cache/src/internal/uploadUtils.ts index 372b2176..efb80de1 100644 --- a/packages/cache/src/internal/uploadUtils.ts +++ b/packages/cache/src/internal/uploadUtils.ts @@ -140,27 +140,30 @@ export async function uploadCacheArchiveSDK( onProgress: uploadProgress.onProgress() } - // try { - uploadProgress.startDisplayTimer() + try { + uploadProgress.startDisplayTimer() - core.debug( - `BlobClient: ${blobClient.name}:${blobClient.accountName}:${blobClient.containerName}` - ) - - const response = await blockBlobClient.uploadFile(archivePath, uploadOptions) - - // TODO: better management of non-retryable errors - if (response._response.status >= 400) { - throw new InvalidResponseError( - `Upload failed with status code ${response._response.status}` + core.debug( + `BlobClient: ${blobClient.name}:${blobClient.accountName}:${blobClient.containerName}` ) - } - return response - // } catch (error) { - // core.debug(`Error uploading cache archive: ${error}`) - // throw error - // } finally { - // uploadProgress.stopDisplayTimer() - // } + const response = await blockBlobClient.uploadFile( + archivePath, + uploadOptions + ) + + // TODO: better management of non-retryable errors + if (response._response.status >= 400) { + throw new InvalidResponseError( + `Upload failed with status code ${response._response.status}` + ) + } + + return response + } catch (error) { + core.debug(`Error uploading cache archive: ${error}`) + throw error + } finally { + uploadProgress.stopDisplayTimer() + } }