Skip to content

Commit 6f2ae50

Browse files
Merge pull request #298 from BrianLPeterson/user/bpet/retryfix7
Adding retries to Invoke-UseCase and GetAzureStackScaleUnitNode.
2 parents b763043 + 5aed9d1 commit 6f2ae50

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

CanaryValidator/Canary.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ while ($runCount -le $NumberOfIterations)
232232
Get-AzsScaleUnit -Location $ResourceLocation
233233
}
234234

235-
Invoke-Usecase -Name 'GetAzureStackScaleUnitNode' -Description "List nodes in scale unit" -UsecaseBlock `
235+
Invoke-Usecase -Name 'GetAzureStackScaleUnitNode' -Description "List nodes in scale unit" -RetryCount 2 -RetryDelayInSec 20 -UsecaseBlock `
236236
{
237237
Get-AzsScaleUnitNode -Location $ResourceLocation
238238
}
@@ -295,7 +295,7 @@ while ($runCount -le $NumberOfIterations)
295295
}
296296
}
297297

298-
if ((Get-Volume ((Get-Item -Path $ENV:TMP).PSDrive.Name)).SizeRemaining/1GB -gt 35)
298+
if ((Get-Volume ((Get-Item -Path $ENV:TMP).PSDrive.Name) -ErrorAction SilentlyContinue).SizeRemaining/1GB -gt 35)
299299
{
300300
[boolean]$invalidUri = $false
301301
try {Invoke-WebRequest -Uri $LinuxImagePath -UseBasicParsing -DisableKeepAlive -Method Head -ErrorAction SilentlyContinue | Out-Null}

CanaryValidator/Canary.Utilities.psm1

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ function Invoke-Usecase
283283
[string]$Description,
284284
[parameter(Mandatory=$true, Position = 2)]
285285
[ValidateNotNullOrEmpty()]
286-
[ScriptBlock]$UsecaseBlock
286+
[ScriptBlock]$UsecaseBlock,
287+
[parameter(Mandatory=$false, Position = 3)]
288+
[int]$RetryCount = 0,
289+
[parameter(Mandatory=$false, Position = 4)]
290+
[int]$RetryDelayInSec = 10
287291
)
288292

289293
if ($Global:listAvailableUsecases)
@@ -324,7 +328,54 @@ function Invoke-Usecase
324328

325329
try
326330
{
327-
$result = Invoke-Command -ScriptBlock $UsecaseBlock
331+
$currentRetryCount = 0
332+
333+
do
334+
{
335+
$useCaseError = $null
336+
337+
try
338+
{
339+
$result = Invoke-Command -ScriptBlock $UsecaseBlock
340+
}
341+
catch
342+
{
343+
$useCaseError = $_
344+
}
345+
346+
# Dont retry or log errors on the parent cases
347+
if ($UsecaseBlock.ToString().Contains("Invoke-Usecase"))
348+
{
349+
$useCaseError = $null
350+
break;
351+
}
352+
353+
if ($useCaseError)
354+
{
355+
$currentRetryCount++
356+
357+
if($currentRetryCount -gt $retryCount)
358+
{
359+
break
360+
}
361+
else
362+
{
363+
Start-Sleep -Seconds $RetryDelayInSec
364+
}
365+
}
366+
}
367+
while($useCaseError)
368+
369+
if ($useCaseError -and $RetryCount -gt 0)
370+
{
371+
throw "Test '$Name' failed and retried '$RetryCount' times. The last exception was: $useCaseError"
372+
}
373+
374+
if ($useCaseError)
375+
{
376+
throw $useCaseError
377+
}
378+
328379
if ($result -and (-not $UsecaseBlock.ToString().Contains("Invoke-Usecase")))
329380
{
330381
Log-Info ($result)

0 commit comments

Comments
 (0)