forked from actions/toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request actions#513 from dhadka/dhadka/download-progress
Display download progress when using Azure Storage SDK
- Loading branch information
Showing
6 changed files
with
400 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import * as core from '@actions/core' | ||
import {DownloadProgress} from '../src/internal/downloadUtils' | ||
|
||
test('download progress tracked correctly', () => { | ||
const progress = new DownloadProgress(1000) | ||
|
||
expect(progress.contentLength).toBe(1000) | ||
expect(progress.receivedBytes).toBe(0) | ||
expect(progress.segmentIndex).toBe(0) | ||
expect(progress.segmentOffset).toBe(0) | ||
expect(progress.segmentSize).toBe(0) | ||
expect(progress.displayedComplete).toBe(false) | ||
expect(progress.timeoutHandle).toBeUndefined() | ||
expect(progress.getTransferredBytes()).toBe(0) | ||
expect(progress.isDone()).toBe(false) | ||
|
||
progress.nextSegment(500) | ||
|
||
expect(progress.contentLength).toBe(1000) | ||
expect(progress.receivedBytes).toBe(0) | ||
expect(progress.segmentIndex).toBe(1) | ||
expect(progress.segmentOffset).toBe(0) | ||
expect(progress.segmentSize).toBe(500) | ||
expect(progress.displayedComplete).toBe(false) | ||
expect(progress.timeoutHandle).toBeUndefined() | ||
expect(progress.getTransferredBytes()).toBe(0) | ||
expect(progress.isDone()).toBe(false) | ||
|
||
progress.setReceivedBytes(250) | ||
|
||
expect(progress.contentLength).toBe(1000) | ||
expect(progress.receivedBytes).toBe(250) | ||
expect(progress.segmentIndex).toBe(1) | ||
expect(progress.segmentOffset).toBe(0) | ||
expect(progress.segmentSize).toBe(500) | ||
expect(progress.displayedComplete).toBe(false) | ||
expect(progress.timeoutHandle).toBeUndefined() | ||
expect(progress.getTransferredBytes()).toBe(250) | ||
expect(progress.isDone()).toBe(false) | ||
|
||
progress.setReceivedBytes(500) | ||
|
||
expect(progress.contentLength).toBe(1000) | ||
expect(progress.receivedBytes).toBe(500) | ||
expect(progress.segmentIndex).toBe(1) | ||
expect(progress.segmentOffset).toBe(0) | ||
expect(progress.segmentSize).toBe(500) | ||
expect(progress.displayedComplete).toBe(false) | ||
expect(progress.timeoutHandle).toBeUndefined() | ||
expect(progress.getTransferredBytes()).toBe(500) | ||
expect(progress.isDone()).toBe(false) | ||
|
||
progress.nextSegment(500) | ||
|
||
expect(progress.contentLength).toBe(1000) | ||
expect(progress.receivedBytes).toBe(0) | ||
expect(progress.segmentIndex).toBe(2) | ||
expect(progress.segmentOffset).toBe(500) | ||
expect(progress.segmentSize).toBe(500) | ||
expect(progress.displayedComplete).toBe(false) | ||
expect(progress.timeoutHandle).toBeUndefined() | ||
expect(progress.getTransferredBytes()).toBe(500) | ||
expect(progress.isDone()).toBe(false) | ||
|
||
progress.setReceivedBytes(250) | ||
|
||
expect(progress.contentLength).toBe(1000) | ||
expect(progress.receivedBytes).toBe(250) | ||
expect(progress.segmentIndex).toBe(2) | ||
expect(progress.segmentOffset).toBe(500) | ||
expect(progress.segmentSize).toBe(500) | ||
expect(progress.displayedComplete).toBe(false) | ||
expect(progress.timeoutHandle).toBeUndefined() | ||
expect(progress.getTransferredBytes()).toBe(750) | ||
expect(progress.isDone()).toBe(false) | ||
|
||
progress.setReceivedBytes(500) | ||
|
||
expect(progress.contentLength).toBe(1000) | ||
expect(progress.receivedBytes).toBe(500) | ||
expect(progress.segmentIndex).toBe(2) | ||
expect(progress.segmentOffset).toBe(500) | ||
expect(progress.segmentSize).toBe(500) | ||
expect(progress.displayedComplete).toBe(false) | ||
expect(progress.timeoutHandle).toBeUndefined() | ||
expect(progress.getTransferredBytes()).toBe(1000) | ||
expect(progress.isDone()).toBe(true) | ||
}) | ||
|
||
test('display timer works correctly', () => { | ||
const progress = new DownloadProgress(1000) | ||
|
||
const infoMock = jest.spyOn(core, 'info') | ||
infoMock.mockImplementation(() => {}) | ||
|
||
const check = (): void => { | ||
expect(infoMock).toHaveBeenLastCalledWith( | ||
expect.stringContaining('Received 500 of 1000') | ||
) | ||
} | ||
|
||
// Validate no further updates are displayed after stopping the timer. | ||
const test2 = (): void => { | ||
check() | ||
expect(progress.timeoutHandle).toBeUndefined() | ||
} | ||
|
||
// Validate the progress is displayed, stop the timer, and call test2. | ||
const test1 = (): void => { | ||
check() | ||
|
||
progress.stopDisplayTimer() | ||
progress.setReceivedBytes(1000) | ||
|
||
setTimeout(() => test2(), 100) | ||
} | ||
|
||
// Start the timer, update the received bytes, and call test1. | ||
const start = (): void => { | ||
progress.startDisplayTimer(10) | ||
expect(progress.timeoutHandle).toBeDefined() | ||
|
||
progress.setReceivedBytes(500) | ||
|
||
setTimeout(() => test1(), 100) | ||
} | ||
|
||
start() | ||
}) | ||
|
||
test('display does not print completed line twice', () => { | ||
const progress = new DownloadProgress(1000) | ||
|
||
const infoMock = jest.spyOn(core, 'info') | ||
infoMock.mockImplementation(() => {}) | ||
|
||
progress.display() | ||
|
||
expect(progress.displayedComplete).toBe(false) | ||
expect(infoMock).toHaveBeenCalledTimes(1) | ||
|
||
progress.nextSegment(1000) | ||
progress.setReceivedBytes(500) | ||
progress.display() | ||
|
||
expect(progress.displayedComplete).toBe(false) | ||
expect(infoMock).toHaveBeenCalledTimes(2) | ||
|
||
progress.setReceivedBytes(1000) | ||
progress.display() | ||
|
||
expect(progress.displayedComplete).toBe(true) | ||
expect(infoMock).toHaveBeenCalledTimes(3) | ||
|
||
progress.display() | ||
|
||
expect(progress.displayedComplete).toBe(true) | ||
expect(infoMock).toHaveBeenCalledTimes(3) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.