Skip to content

Commit 7daebc3

Browse files
authored
Removed $lastexitcode due to unexpected issues on non-windows systems (#21091)
* Reverted cmdlet error check and added -Force for New-AzResourceGroup * Removed the $lastexitcode due to unexpected issues on non-windows system * Modified cleanup jobs info
1 parent 5d82b27 commit 7daebc3

File tree

4 files changed

+18
-27
lines changed

4 files changed

+18
-27
lines changed

src/Compute/Compute.Test/LiveTests/TestLiveScenarios.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ Invoke-LiveTestScenario -Name "Delete a ssh key" -Description "Test deleting a s
164164

165165
New-AzSshKey -ResourceGroupName $rgName -Name $key1Name
166166
Remove-AzSshKey -ResourceGroupName $rgName -name $key1Name
167-
$actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key1Name
167+
$actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key1Name -ErrorAction SilentlyContinue
168168
Assert-Null $actual
169169

170170
$key2 = New-AzSshKey -ResourceGroupName $rgName -Name $key2Name
171171
Remove-AzSshKey -ResourceId $key2.Id
172-
$actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key2Name
172+
$actual = Get-AzSshKey -ResourceGroupName $rgName -Name $key2Name -ErrorAction SilentlyContinue
173173
Assert-Null $actual
174174
}

tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ function InvokeLocalLiveTestScenarios {
5656
Write-Host "##[section]All cleanup jobs are completed." -ForegroundColor Green
5757

5858
Write-Host "##[group]Cleanup jobs information." -ForegroundColor Green
59+
60+
Write-Host
5961
$cleanupJobs = Get-Job
6062
$cleanupJobs | Select-Object Name, Command, State, PSBeginTime, PSEndTime, Output
63+
Write-Host
64+
6165
Write-Host "##[endgroup]"
6266

6367
$cleanupJobs | Remove-Job

tools/TestFx/Live/InvokeLiveTestScenarios.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,17 @@ $liveScenarios | ForEach-Object {
9393

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

101100
Write-Host "##[group]Cleanup jobs information." -ForegroundColor Green
101+
102+
Write-Host
102103
$cleanupJobs = Get-Job
103104
$cleanupJobs | Select-Object Name, Command, State, PSBeginTime, PSEndTime, Output
105+
Write-Host
106+
104107
Write-Host "##[endgroup]"
105108

106109
$cleanupJobs | Remove-Job

tools/TestFx/Live/LiveTestUtility.psm1

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ function Invoke-LiveTestCommand {
183183

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

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

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

193193
$cmdResult
194194
break
@@ -243,7 +243,7 @@ function Invoke-LiveTestScenario {
243243
throw "Error occurred when initializing live tests. The csv file was not found."
244244
}
245245

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

248248
try {
249249
$snrCsvData = [PSCustomObject]@{
@@ -267,13 +267,13 @@ function Invoke-LiveTestScenario {
267267
$snrResourceGroupLocation = $ResourceGroupLocation
268268
}
269269

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

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

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

279279
$snrRetryCount = 0
@@ -288,12 +288,8 @@ function Invoke-LiveTestScenario {
288288

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

291-
if ($LASTEXITCODE -eq 0) {
292-
Write-Host "##[section]Successfully executed the live scenario `"$Name`"." -ForegroundColor Green
293-
}
294-
else {
295-
throw "Error occurred when executing the live scenario `"$Name`"."
296-
}
291+
Write-Host "##[section]Finish executing the live scenario `"$Name`"." -ForegroundColor Green
292+
297293
break
298294
}
299295
catch {
@@ -303,18 +299,6 @@ function Invoke-LiveTestScenario {
303299

304300
$snrInvocationInfo = $snrErrorRecord.InvocationInfo
305301

306-
Write-Host "##[error]Error Object:" -ForegroundColor Red
307-
$_ | Format-List * -Force
308-
309-
Write-Host "##[error]Exception Object:" -ForegroundColor Red
310-
$_.Exception.InnerException | Format-List * -Force
311-
312-
Write-Host "##[error]Error Record:" -ForegroundColor Red
313-
$snrErrorRecord | Format-List * -Force
314-
315-
Write-Host "##[error]Invocation Info:" -ForegroundColor Red
316-
$snrInvocationInfo | Format-List * -Force
317-
318302
if ($null -ne $snrInvocationInfo) {
319303
$snrScriptName = Split-Path -Path $snrInvocationInfo.ScriptName -Leaf -ErrorAction SilentlyContinue
320304
if ($snrScriptName -eq "Assert.ps1") {
@@ -362,7 +346,7 @@ function Invoke-LiveTestScenario {
362346

363347
if (!$NoResourceGroup.IsPresent -and $null -ne $snrResourceGroup) {
364348
try {
365-
Write-Host "##[section]Start to clean up the resource group `"$snrResourceGroupName`"." -ForegroundColor Green
349+
Write-Host "##[section]Start cleaning up the resource group `"$snrResourceGroupName`"." -ForegroundColor Green
366350
Clear-LiveTestResources -Name $snrResourceGroupName
367351
}
368352
catch {

0 commit comments

Comments
 (0)