Skip to content

Removed $lastexitcode due to unexpected issues on non-windows systems #21091

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 4 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/Compute/Compute.Test/LiveTests/TestLiveScenarios.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ Invoke-LiveTestScenario -Name "Delete a ssh key" -Description "Test deleting a s

New-AzSshKey -ResourceGroupName $rgName -Name $key1Name
Remove-AzSshKey -ResourceGroupName $rgName -name $key1Name
$actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key1Name
$actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key1Name -ErrorAction SilentlyContinue
Assert-Null $actual

$key2 = New-AzSshKey -ResourceGroupName $rgName -Name $key2Name
Remove-AzSshKey -ResourceId $key2.Id
$actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key2Name
$actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key2Name -ErrorAction SilentlyContinue
Assert-Null $actual
}
4 changes: 4 additions & 0 deletions tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ function InvokeLocalLiveTestScenarios {
Write-Host "##[section]All cleanup jobs are completed." -ForegroundColor Green

Write-Host "##[group]Cleanup jobs information." -ForegroundColor Green

Write-Host
$cleanupJobs = Get-Job
$cleanupJobs | Select-Object Name, Command, State, PSBeginTime, PSEndTime, Output
Write-Host

Write-Host "##[endgroup]"

$cleanupJobs | Remove-Job
Expand Down
5 changes: 4 additions & 1 deletion tools/TestFx/Live/InvokeLiveTestScenarios.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ $liveScenarios | ForEach-Object {

Write-Host "##[section]Waiting for all cleanup jobs to be completed." -ForegroundColor Green
while (Get-Job -State Running) {
Write-Host "[section]Waiting for 30 seconds ..." -ForegroundColor Green
Start-Sleep -Seconds 30
}
Write-Host "##[section]All cleanup jobs are completed." -ForegroundColor Green

Write-Host "##[group]Cleanup jobs information." -ForegroundColor Green

Write-Host
$cleanupJobs = Get-Job
$cleanupJobs | Select-Object Name, Command, State, PSBeginTime, PSEndTime, Output
Write-Host

Write-Host "##[endgroup]"

$cleanupJobs | Remove-Job
32 changes: 8 additions & 24 deletions tools/TestFx/Live/LiveTestUtility.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ function Invoke-LiveTestCommand {

do {
try {
Write-Host "##[section]Start to execute the command `"$Command`"." -ForegroundColor Green
Write-Host "##[section]Start executing the command `"$Command`"." -ForegroundColor Green
Write-Host "##[command]The command `"$Command`" is running." -ForegroundColor Cyan

$cmdResult = Invoke-Expression -Command $Command -ErrorAction Stop

Write-Host "##[section]Successfully executed the command `"$Command`"" -ForegroundColor Green
Write-Host "##[section]Finish executing the command `"$Command`"" -ForegroundColor Green

$cmdResult
break
Expand Down Expand Up @@ -243,7 +243,7 @@ function Invoke-LiveTestScenario {
throw "Error occurred when initializing live tests. The csv file was not found."
}

Write-Host "##[group]Start to execute the live scenario `"$Name`"." -ForegroundColor Green
Write-Host "##[group]Start executing the live scenario `"$Name`"." -ForegroundColor Green

try {
$snrCsvData = [PSCustomObject]@{
Expand All @@ -267,13 +267,13 @@ function Invoke-LiveTestScenario {
$snrResourceGroupLocation = $ResourceGroupLocation
}

Write-Host "##[section]Start to create a resource group." -ForegroundColor Green
Write-Host "##[section]Start creating a resource group." -ForegroundColor Green
Write-Host "##[section]Resource group name: $snrResourceGroupName" -ForegroundColor Green
Write-Host "##[section]Resource group location: $snrResourceGroupLocation" -ForegroundColor Green

$snrResourceGroup = New-LiveTestResourceGroup -Name $snrResourceGroupName -Location $snrResourceGroupLocation

Write-Host "##[section]Successfully created the resource group." -ForegroundColor Green
Write-Host "##[section]Finish creating the resource group." -ForegroundColor Green
}

$snrRetryCount = 0
Expand All @@ -288,12 +288,8 @@ function Invoke-LiveTestScenario {

$ScenarioScript.InvokeWithContext($null, $prefs, $snrResourceGroup)

if ($LASTEXITCODE -eq 0) {
Write-Host "##[section]Successfully executed the live scenario `"$Name`"." -ForegroundColor Green
}
else {
throw "Error occurred when executing the live scenario `"$Name`"."
}
Write-Host "##[section]Finish executing the live scenario `"$Name`"." -ForegroundColor Green

break
}
catch {
Expand All @@ -303,18 +299,6 @@ function Invoke-LiveTestScenario {

$snrInvocationInfo = $snrErrorRecord.InvocationInfo

Write-Host "##[error]Error Object:" -ForegroundColor Red
$_ | Format-List * -Force

Write-Host "##[error]Exception Object:" -ForegroundColor Red
$_.Exception.InnerException | Format-List * -Force

Write-Host "##[error]Error Record:" -ForegroundColor Red
$snrErrorRecord | Format-List * -Force

Write-Host "##[error]Invocation Info:" -ForegroundColor Red
$snrInvocationInfo | Format-List * -Force

if ($null -ne $snrInvocationInfo) {
$snrScriptName = Split-Path -Path $snrInvocationInfo.ScriptName -Leaf -ErrorAction SilentlyContinue
if ($snrScriptName -eq "Assert.ps1") {
Expand Down Expand Up @@ -362,7 +346,7 @@ function Invoke-LiveTestScenario {

if (!$NoResourceGroup.IsPresent -and $null -ne $snrResourceGroup) {
try {
Write-Host "##[section]Start to clean up the resource group `"$snrResourceGroupName`"." -ForegroundColor Green
Write-Host "##[section]Start cleaning up the resource group `"$snrResourceGroupName`"." -ForegroundColor Green
Clear-LiveTestResources -Name $snrResourceGroupName
}
catch {
Expand Down