From ae026cf7c6179a206fc6bd24fd5521b78331c385 Mon Sep 17 00:00:00 2001 From: Sampark Sharma Date: Fri, 10 Feb 2023 11:52:49 +0000 Subject: [PATCH] Fix bugs --- packages/cache/src/internal/downloadUtils.ts | 13 +++++++------ packages/cache/src/internal/requestUtils.ts | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/cache/src/internal/downloadUtils.ts b/packages/cache/src/internal/downloadUtils.ts index 5cee37d7..1f3d5b78 100644 --- a/packages/cache/src/internal/downloadUtils.ts +++ b/packages/cache/src/internal/downloadUtils.ts @@ -10,7 +10,7 @@ import * as util from 'util' import * as utils from './cacheUtils' import {SocketTimeout} from './constants' import {DownloadOptions} from '../options' -import {retryHttpClientResponse} from './requestUtils' +import {retryHttpClientResponse, sleep} from './requestUtils' import {AbortController} from '@azure/abort-controller' @@ -162,22 +162,23 @@ export class DownloadProgress { } async function displayDownloadProgress(socket: any, startTime: number): Promise { - while(!socket.complete) { - const transferredBytes = socket.bytesRead + while(!socket.destroyed) { + const byteRead = socket.bytesRead const totalBytes = 100000 - const percentage = (100 * (transferredBytes / totalBytes)).toFixed( + const percentage = (100 * (byteRead / totalBytes)).toFixed( 1 ) const elapsedTime = Date.now() - startTime const downloadSpeed = ( - transferredBytes / + byteRead / (1024 * 1024) / (elapsedTime / 1000) ).toFixed(1) core.info( - `Received ${transferredBytes} of ${totalBytes} (${percentage}%), ${downloadSpeed} MBs/sec` + `Received ${byteRead} of ${totalBytes} (${percentage}%), ${downloadSpeed} MBs/sec` ) + sleep(10) } } diff --git a/packages/cache/src/internal/requestUtils.ts b/packages/cache/src/internal/requestUtils.ts index 043c8a7c..85535571 100644 --- a/packages/cache/src/internal/requestUtils.ts +++ b/packages/cache/src/internal/requestUtils.ts @@ -33,7 +33,7 @@ export function isRetryableStatusCode(statusCode?: number): boolean { return retryableStatusCodes.includes(statusCode) } -async function sleep(milliseconds: number): Promise { +export async function sleep(milliseconds: number): Promise { return new Promise(resolve => setTimeout(resolve, milliseconds)) }