Skip to content

Commit 5e8064d

Browse files
authored
Updated live test to use jobs for resource cleanup (#21070)
1 parent a06dbc9 commit 5e8064d

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

.azure-pipelines/util/live-test-steps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ parameters:
66

77
jobs:
88
- job: ${{ parameters.name }}
9-
timeoutInMinutes: 360
9+
timeoutInMinutes: 600
1010
pool:
1111
vmImage: ${{ parameters.vmImage }}
1212

tools/TestFx/Live/InvokeLiveTestScenarios.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,17 @@ $liveScenarios | ForEach-Object {
9090
. $_.FullName
9191
FillLiveTestCoverageAdditionalInfo -TestCoverageDataLocation $dataLocation -BuildId $BuildId -OSVersion $OSVersion -PSVersion $PSVersion -ModuleName $moduleName
9292
}
93+
94+
Write-Host "##[section]Waiting for all cleanup jobs to be completed." -ForegroundColor Green
95+
while (Get-Job -State Running) {
96+
Write-Host "[section]Waiting for 10 seconds ..." -ForegroundColor Green
97+
Start-Sleep -Seconds 10
98+
}
99+
Write-Host "##[section]All cleanup jobs are completed." -ForegroundColor Green
100+
101+
Write-Host "##[group]Cleanup jobs information." -ForegroundColor Green
102+
$cleanupJobs = Get-Job
103+
$cleanupJobs | Select-Object Name, Command, State, PSBeginTime, PSEndTime, Output
104+
Write-Host "##[endgroup]"
105+
106+
$cleanupJobs | Remove-Job

tools/TestFx/Live/LiveTestUtility.psm1

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

184184
do {
185185
try {
186-
Write-Host "##[section]Start to execute the command `"$Command`"" -ForegroundColor Green
187-
Write-Host "##[command]The command `"$Command`" is running" -ForegroundColor Cyan
186+
Write-Host "##[section]Start to execute the command `"$Command`"." -ForegroundColor Green
187+
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+
if ($LASTEXITCODE -eq 0) {
192+
Write-Host "##[section]Successfully executed the command `"$Command`"" -ForegroundColor Green
193+
}
194+
else {
195+
throw "Error occurred when executing the command `"$Command`"."
196+
}
197+
192198
$cmdResult
193199
break
194200
}
@@ -280,14 +286,19 @@ function Invoke-LiveTestScenario {
280286

281287
do {
282288
try {
283-
$sPrefs = @([psvariable]::new("ErrorActionPreference", "Stop"), [psvariable]::new("ConfirmPreference", "None"))
289+
$prefs = @([psvariable]::new("ErrorActionPreference", "Stop"), [psvariable]::new("ConfirmPreference", "None"))
284290
if ($snrRetryCount -eq $script:ScenarioMaxRetryCount) {
285291
$prefs += [psvariable]::new("DebugPreference", "Continue")
286292
}
287293

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

290-
Write-Host "##[section]Successfully executed the live scenario `"$Name`"." -ForegroundColor Green
296+
if ($LASTEXITCODE -eq 0) {
297+
Write-Host "##[section]Successfully executed the live scenario `"$Name`"." -ForegroundColor Green
298+
}
299+
else {
300+
throw "Error occurred when executing the live scenario `"$Name`"."
301+
}
291302
break
292303
}
293304
catch {
@@ -377,7 +388,7 @@ function Clear-LiveTestResources {
377388
[string] $Name
378389
)
379390

380-
Invoke-LiveTestCommand -Command "Remove-AzResourceGroup -Name $Name -Force"
391+
Invoke-LiveTestCommand -Command "Remove-AzResourceGroup -Name $Name -Force -AsJob"
381392
}
382393

383394
function ConvertToLiveTestJsonErrors {

0 commit comments

Comments
 (0)