Skip to content

Shared/livetest #20714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions tools/TestFx/Live/LiveTestUtility.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ New-Variable -Name LiveTestRawCsvFile -Value (Join-Path -Path $script:LiveTestRa

function InitializeLiveTestModule {
[CmdletBinding()]
param (
[Parameter(Mandatory, Position = 0)]
[ValidateNotNullOrEmpty()]
[string] $ModuleName
)
param ()

if (!(Test-Path -LiteralPath $script:LiveTestAnalysisDirectory -PathType Container)) {
New-Item -Path $script:LiveTestAnalysisDirectory -ItemType Directory -Force
Expand Down Expand Up @@ -235,7 +231,7 @@ function Invoke-LiveTestScenario {

do {
try {
$ScenarioScript.InvokeWithContext($null, [PSVariable]::new("ErrorActionPreference", "Stop"), $snrResourceGroup)
$ScenarioScript.InvokeWithContext($null, @([psvariable]::new("ErrorActionPreference", "Stop"), [psvariable]::new("ConfirmPreference", "None")), $snrResourceGroup)
Write-Host "##[section]Successfully executed the live scenario `"$Name`"." -ForegroundColor Green
break
}
Expand All @@ -246,23 +242,30 @@ function Invoke-LiveTestScenario {

$snrInvocationInfo = $snrErrorRecord.InvocationInfo
if ($null -ne $snrInvocationInfo) {
$snrErrorDetails += " thrown at line:$($snrInvocationInfo.ScriptLineNumber) char:$($snrInvocationInfo.OffsetInLine) by cmdlet `"$($snrInvocationInfo.InvocationName)`" on `"$($snrInvocationInfo.Line.ToString().Trim())`"."
$snrScriptName = Split-Path -Path $snrInvocationInfo.ScriptName -Leaf -ErrorAction SilentlyContinue
if ($snrScriptName -eq "Assert.ps1") {
Write-Host "##[error]Exception was thrown from the Assert.ps1. The stack trace is:" -ForegroundColor Red
Write-Host "##[error]$($snrErrorRecord.ScriptStackTrace)" -ForegroundColor Red
}
else {
$snrErrorDetails += " thrown at line:$($snrInvocationInfo.ScriptLineNumber) char:$($snrInvocationInfo.OffsetInLine) by cmdlet '$($snrInvocationInfo.MyCommand)' on '$($snrInvocationInfo.Line.ToString().Trim())'"
}
}

$snrRetryErrors += $snrErrorDetails

if ($snrRetryCount -lt $script:ScenarioMaxRetryCount) {
$snrRetryCount++
$exponentialDelay = [Math]::Min((1 -shl ($snrRetryCount - 1)) * [int](Get-Random -Minimum ($script:ScenarioDelay * 0.8) -Maximum ($script:ScenarioDelay * 1.2)), $script:ScenarioMaxDelay)
Write-Host "##[warning]Error occurred when executing the live scenario `"$Name`" with error message `"$snrErrorMessage`"." -ForegroundColor Yellow
Write-Host "##[warning]Error occurred when executing the live scenario `"$Name`" with error details `"$snrErrorDetails`"." -ForegroundColor Yellow
Write-Host "##[warning]Live test will retry automatically in $exponentialDelay seconds." -ForegroundColor Yellow
Write-Host

Start-Sleep -Seconds $exponentialDelay
Write-Host "##[warning]Retry #$snrRetryCount to execute the live scenario `"$Name`"." -ForegroundColor Yellow
}
else {
Write-Host "##[error]Failed to execute the live scenario `"$Name`" with error message `"$snrErrorMessage`"." -ForegroundColor Red
Write-Host "##[error]Failed to execute the live scenario `"$Name`" with error details `"$snrErrorDetails`"." -ForegroundColor Red
Write-Host
$snrCsvData.IsSuccess = $false
$snrCsvData.Errors = ConvertToLiveTestJsonErrors -Errors $snrRetryErrors
Expand All @@ -274,7 +277,7 @@ function Invoke-LiveTestScenario {
}
catch {
$snrErrorMessage = $_.Exception.Message
Write-Host "##[error]Error occurred when executing the live scenario `"$Name`" with error message `"$snrErrorMessage`"" -ForegroundColor Red
Write-Host "##[error]Error occurred when executing the live scenario `"$Name`" with error details `"$snrErrorDetails`"" -ForegroundColor Red
Write-Host
$snrCsvData.IsSuccess = $false
$snrCsvData.Errors = ConvertToLiveTestJsonErrors -Errors $snrErrorMessage
Expand Down Expand Up @@ -327,4 +330,4 @@ function ConvertToLiveTestJsonErrors {
(ConvertTo-Json $errorsObj -Compress)
}

InitializeLiveTestModule -ModuleName $ModuleName
InitializeLiveTestModule