File tree Expand file tree Collapse file tree 2 files changed +23
-7
lines changed
containers-toolkit/Private Expand file tree Collapse file tree 2 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -253,9 +253,11 @@ Describe "CommonToolUtilities.psm1" {
253
253
It " Should throw an error if download fails" {
254
254
$errorMessage = " Response status code does not indicate success: 404 (Not Found)."
255
255
Mock Invoke-WebRequest { Throw $errorMessage } - ModuleName " CommonToolUtilities"
256
+ Mock Start-Sleep - ModuleName " CommonToolUtilities"
256
257
257
258
{ Get-InstallationFile - FileParameters $Script :MockFiles } | Should - Throw " Failed to download asset*"
258
- $Error [1 ].Exception.Message | Should - BeLike " Failed to download assets for `" v2.0.0-rc.1`" . Couldn`' t download `" v2.0.0-rc.1`" release assets.*"
259
+ Should - Invoke Invoke-WebRequest - Times 3 - Scope It - ModuleName " CommonToolUtilities"
260
+ $Error [1 ].Exception.Message | Should - BeLike " Failed to download assets for `" v2.0.0-rc.1`" . Couldn`' t download `" v2.0.0-rc.1`" release assets*"
259
261
}
260
262
}
261
263
Original file line number Diff line number Diff line change @@ -205,12 +205,26 @@ function Get-InstallationFile {
205
205
begin {
206
206
function Receive-File {
207
207
param ($params )
208
- try {
209
- Invoke-WebRequest - Uri $params.Uri - OutFile $params.DownloadPath - UseBasicParsing - MaximumRetryCount 3 - RetryIntervalSec 60
210
- }
211
- catch {
212
- Throw " Couldn't download `" $ ( $params.Feature ) `" release assets. `" $ ( $params.Uri ) `" .`n $ ( $_.Exception.Message ) "
213
- }
208
+
209
+ $MaximumRetryCount = 3
210
+ $RetryIntervalSec = 60
211
+ $lastError = $null # Store the last exception
212
+
213
+ do {
214
+ try {
215
+ Invoke-WebRequest - Uri $params.Uri - OutFile $params.DownloadPath - UseBasicParsing
216
+ return
217
+ }
218
+ catch {
219
+ $lastError = $_ # Store the last error for proper exception handling
220
+ Write-Warning " Failed to download `" $ ( $params.Feature ) `" release assets. Retrying... ($MaximumRetryCount retries left)"
221
+ Start-Sleep - Seconds $RetryIntervalSec
222
+ $MaximumRetryCount -= 1
223
+ }
224
+ } while ($MaximumRetryCount -gt 0 )
225
+
226
+ # Throw the last encountered error after all retries fail
227
+ Throw " Couldn't download `" $ ( $params.Feature ) `" release assets from `" $ ( $params.Uri ) `" .`n $ ( $lastError.Exception.Message ) "
214
228
}
215
229
216
230
function DownloadAssets {
You can’t perform that action at this time.
0 commit comments