Skip to content

Commit 607df6c

Browse files
authored
Implemented multi-threading for live test (#21646)
* Implemented multi-threading for live test and changed design for email notification * Added comment for updating clean up interval. * Renamed Import-KustoDataFromCsv to Add-KustoData * Renamed Import-KustoDataFromCsv for test coverage
1 parent 07a0b8e commit 607df6c

11 files changed

+421
-332
lines changed

.azure-pipelines/live-test.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ parameters:
4343
variables:
4444
ArtifactsName: LiveTestArtifacts
4545
DataLocation: $(Pipeline.Workspace)/$(ArtifactsName)
46+
SuppressAzurePowerShellBreakingChangeWarnings: true
4647

4748
schedules:
4849
- cron: "0 19 * * *"
@@ -173,15 +174,28 @@ stages:
173174

174175
- stage: Report
175176
displayName: Send Report
176-
dependsOn: Test
177177
jobs:
178178
- job:
179179
displayName: Send Live Test Status Report
180180
steps:
181+
- task: PowerShell@2
182+
displayName: Create data location directory
183+
inputs:
184+
pwsh: true
185+
targetType: inline
186+
script:
187+
New-Item -Name $(ArtifactsName) -Path $(Pipeline.Workspace) -ItemType Directory -Force
188+
189+
- task: DownloadPipelineArtifact@2
190+
displayName: Download live test results
191+
inputs:
192+
buildType: 'current'
193+
targetPath: $(Pipeline.Workspace)/$(ArtifactsName)
194+
181195
- task: PowerShell@2
182196
displayName: Send live test report
183197
inputs:
184198
pwsh: true
185199
targetType: filePath
186200
filePath: ./tools/TestFx/Live/SendLiveTestReport.ps1
187-
arguments: $(KustoServicePrincipalTenantId) $(KustoServicePrincipalId) $(KustoServicePrincipalSecret) $(KustoClusterName) $(KustoClusterRegion) $(LiveTestDatabaseName) $(LiveTestTableName) $(Build.BuildId) "$(EmailServiceConnectionString)" "$(EmailFrom)" "$(EmailTo)"
201+
arguments: -EmailServiceConnectionString '$(EmailServiceConnectionString)' -EmailFrom '$(EmailFrom)'

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ jobs:
1313

1414
steps:
1515
- task: UseDotNet@2
16-
condition: ne('${{ parameters.dotnetVersion }}', '')
1716
displayName: Install desired .NET version ${{ parameters.dotnetVersion }}
17+
condition: ne('${{ parameters.dotnetVersion }}', '')
1818
inputs:
1919
packageType: sdk
2020
version: ${{ parameters.dotnetVersion }}
2121

2222
- task: PowerShell@2
2323
displayName: Install desired Powershell version ${{ parameters.psVersion }}
24+
condition: ne('${{ parameters.psVersion }}', '')
2425
inputs:
2526
pwsh: true
2627
targetType: filePath
@@ -29,14 +30,15 @@ jobs:
2930

3031
- task: PowerShell@2
3132
displayName: Create live test data location directory
33+
condition: ne(variables['skipLatest'], 'true')
3234
inputs:
3335
pwsh: true
3436
targetType: inline
3537
script:
3638
New-Item -Name $(ArtifactsName) -Path $(Pipeline.Workspace) -ItemType Directory -Force
3739

3840
- task: DownloadPipelineArtifact@2
39-
condition: and(succeeded(), eq(variables['GalleryName'], 'DailyBuild'), eq(variables['PipelineBuildId'], ''))
41+
condition: and(succeeded(), ne(variables['skipLatest'], 'true'), eq(variables['GalleryName'], 'DailyBuild'), eq(variables['PipelineBuildId'], ''))
4042
displayName: Download latest artifacts from daily build pipeline main branch
4143
inputs:
4244
buildType: 'specific'
@@ -48,7 +50,7 @@ jobs:
4850
targetPath: $(Pipeline.Workspace)
4951

5052
- task: DownloadPipelineArtifact@2
51-
condition: and(succeeded(), eq(variables['GalleryName'], 'DailyBuild'), ne(variables['PipelineBuildId'], ''))
53+
condition: and(succeeded(), ne(variables['skipLatest'], 'true'), eq(variables['GalleryName'], 'DailyBuild'), ne(variables['PipelineBuildId'], ''))
5254
displayName: Download specific artifacts from daily build pipeline
5355
inputs:
5456
buildType: 'specific'
@@ -60,7 +62,7 @@ jobs:
6062
targetPath: $(Pipeline.Workspace)
6163

6264
- task: DownloadPipelineArtifact@2
63-
condition: and(succeeded(), eq(variables['GalleryName'], 'Sign'), eq(variables['PipelineBuildId'], ''))
65+
condition: and(succeeded(), ne(variables['skipLatest'], 'true'), eq(variables['GalleryName'], 'Sign'), eq(variables['PipelineBuildId'], ''))
6466
displayName: Download latest artifacts from sign pipeline internal/release branch
6567
inputs:
6668
buildType: 'specific'
@@ -72,7 +74,7 @@ jobs:
7274
targetPath: $(Pipeline.Workspace)
7375

7476
- task: DownloadPipelineArtifact@2
75-
condition: and(succeeded(), eq(variables['GalleryName'], 'Sign'), ne(variables['PipelineBuildId'], ''))
77+
condition: and(succeeded(), ne(variables['skipLatest'], 'true'), eq(variables['GalleryName'], 'Sign'), ne(variables['PipelineBuildId'], ''))
7678
displayName: Download specific artifacts from sign pipeline
7779
inputs:
7880
buildType: 'specific'
@@ -84,7 +86,7 @@ jobs:
8486
targetPath: $(Pipeline.Workspace)
8587

8688
- task: PowerShell@2
87-
condition: and(succeeded(), ne(variables['GalleryName'], 'PSGallery'))
89+
condition: and(succeeded(), ne(variables['skipLatest'], 'true'), ne(variables['GalleryName'], 'PSGallery'))
8890
displayName: Copy artifacts to local repository
8991
inputs:
9092
pwsh: true
@@ -97,6 +99,7 @@ jobs:
9799
98100
- task: PowerShell@2
99101
displayName: Install desired Az module from $(GalleryName)
102+
condition: and(succeeded(), ne(variables['skipLatest'], 'true'))
100103
inputs:
101104
pwsh: true
102105
targetType: filePath
@@ -105,6 +108,7 @@ jobs:
105108

106109
- task: PowerShell@2
107110
displayName: Connect Azure with live test service principal
111+
condition: and(succeeded(), ne(variables['skipLatest'], 'true'))
108112
inputs:
109113
pwsh: true
110114
targetType: filePath
@@ -114,28 +118,26 @@ jobs:
114118
retryCountOnTaskFailure: 3
115119

116120
- task: PowerShell@2
117-
displayName: Run top E2E live scenarios
121+
displayName: Run end-to-end live scenarios
122+
condition: and(succeeded(), ne(variables['skipLatest'], 'true'))
118123
inputs:
119124
pwsh: true
120125
targetType: filePath
121126
filePath: ./tools/TestFx/Live/InvokeLiveTestCITask.ps1
122-
arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InvokeLiveTestScenarios.ps1 -RunPlatform ${{ parameters.osType }} -RunPowerShell ${{ parameters.psVersion }} -PowerShellLatest $(PowerShellLatest) -RepoLocation $(Build.SourcesDirectory) -DataLocation $(DataLocation)'
123-
retryCountOnTaskFailure: 3
127+
arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InvokeLiveTestScenarios.ps1 -OSVersion ${{ parameters.vmImage }} -RunPlatform ${{ parameters.osType }} -RunPowerShell ${{ parameters.psVersion }}'
124128

125129
- task: PowerShell@2
126130
displayName: Save live test results to Kusto
127-
condition: and(succeededOrFailed(), eq(variables['Build.Reason'], 'Schedule'))
131+
condition: and(succeeded(), ne(variables['skipLatest'], 'true'), or(eq(variables['Build.Reason'], 'Schedule'), eq(variables['Build.SourceBranch'], 'refs/heads/internal/release')))
128132
inputs:
129133
pwsh: true
130134
targetType: filePath
131135
filePath: ./tools/TestFx/Live/SaveLiveTestResult.ps1
132-
arguments: $(KustoServicePrincipalTenantId) $(KustoServicePrincipalId) $(KustoServicePrincipalSecret) $(KustoClusterName) $(KustoClusterRegion) $(LiveTestDatabaseName) $(LiveTestTableName) $(DataLocation) $(Build.BuildId) ${{ parameters.vmImage }} "$(Tag)"
133-
failOnStderr: true
134-
retryCountOnTaskFailure: 3
136+
arguments: $(KustoServicePrincipalTenantId) $(KustoServicePrincipalId) $(KustoServicePrincipalSecret) $(KustoClusterName) $(KustoClusterRegion)
135137

136138
- task: PublishPipelineArtifact@1
137139
displayName: Publish live test results to pipeline artifact
140+
condition: and(succeeded(), ne(variables['skipLatest'], 'true'))
138141
inputs:
139142
artifact: livetest-os-${{ parameters.vmImage }}-ps-${{ replace(parameters.psVersion, '*', 'x') }}
140143
targetPath: $(DataLocation)
141-
condition: always()

tools/TestFx/Coverage/SaveTestCoverageResult.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ if (Test-Path -LiteralPath $cvgDir -PathType Container) {
5353
Export-Csv -Path $_ -Encoding utf8 -NoTypeInformation -Force
5454
}
5555

56-
Import-KustoDataFromCsv -DatabaseName ${env:TESTCOVERAGEDATABASENAME} -TableName ${env:TESTCOVERAGETABLENAME} -CsvFile $cvgRawCsv
56+
Add-KustoData -DatabaseName ${env:TESTCOVERAGEDATABASENAME} -TableName ${env:TESTCOVERAGETABLENAME} -CsvFile $cvgRawCsv
5757
}
5858
else {
5959
Write-Host "##[warning]No test coverage data was found." -ForegroundColor Yellow

tools/TestFx/Live/InitializeLiveTestEnvironment.ps1

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,42 @@ param(
44
[string] $DesiredVersion
55
)
66

7+
& (Join-Path -Path ($PSScriptRoot | Split-Path) -ChildPath "Utilities" | Join-Path -ChildPath "CommonUtility.ps1")
8+
79
$winPSVersion = "5.1"
810
$isWinPSDesired = $DesiredVersion -eq $winPSVersion
911

10-
function InstallLiveTestDesiredPowerShell {
11-
[CmdletBinding()]
12-
param (
13-
[Parameter(Mandatory)]
14-
[ValidateNotNullOrEmpty()]
15-
[string] $DesiredVersion
16-
)
12+
Write-Host "Validating desired PowerShell version."
1713

18-
Write-Host "Validating desired PowerShell version."
14+
if ($isWinPSDesired) {
15+
powershell -NoLogo -NoProfile -NonInteractive -Command "(Get-Variable -Name PSVersionTable).Value"
16+
Write-Host "##[section]Desired Windows Powershell version $DesiredVersion has been installed."
17+
}
18+
else {
19+
Write-Host "##[section]Installing PowerShell version $DesiredVersion."
1920

20-
if ($isWinPSDesired) {
21-
powershell -NoLogo -NoProfile -NonInteractive -Command "(Get-Variable -Name PSVersionTable).Value"
22-
Write-Host "##[section]Desired Windows Powershell version $DesiredVersion has been installed."
21+
dotnet --version
22+
dotnet new tool-manifest --force
23+
if ($DesiredVersion -eq "latest") {
24+
dotnet tool install powershell
2325
}
2426
else {
25-
Write-Host "##[section]Installing PowerShell version $DesiredVersion."
26-
27-
dotnet --version
28-
dotnet new tool-manifest --force
29-
if ($DesiredVersion -eq "latest") {
30-
dotnet tool install powershell
31-
}
32-
else {
33-
dotnet tool install powershell --version $DesiredVersion
34-
}
35-
dotnet tool list
27+
dotnet tool install powershell --version $DesiredVersion
28+
}
29+
dotnet tool list
3630

37-
dotnet tool run pwsh -Version
31+
dotnet tool run pwsh -Version
3832

39-
Write-Host "##[section]Desired PowerShell version $DesiredVersion has been installed."
40-
}
33+
Write-Host "##[section]Desired PowerShell version $DesiredVersion has been installed."
4134
}
4235

43-
function RemoveLiveTestPreInstalledModule {
44-
[CmdletBinding()]
45-
param(
46-
[Parameter(Mandatory, Position = 0)]
47-
[Alias("ModuleName")]
48-
[ValidateNotNullOrEmpty()]
49-
[string] $Name
50-
)
51-
52-
# Remove Az modules
53-
Get-Module -Name $Name* -ListAvailable | ForEach-Object {
54-
$moduleDirectory = $_.Path | Split-Path | Split-Path
55-
if (Test-Path -LiteralPath $moduleDirectory) {
56-
Remove-Item -LiteralPath $moduleDirectory -Recurse -Force
57-
}
36+
if ($DesiredVersion -eq "latest") {
37+
$curMajorVer = dotnet tool run pwsh -NoLogo -NoProfile -NonInteractive -Command "(Get-Variable -Name PSVersionTable -ValueOnly).PSVersion.Major"
38+
$curMinorVer = dotnet tool run pwsh -NoLogo -NoProfile -NonInteractive -Command "(Get-Variable -Name PSVersionTable -ValueOnly).PSVersion.Minor"
39+
$curSimpleVer = "$curMajorVer.$curMinorVer"
40+
41+
if ($curSimpleVer -eq ${env:POWERSHELLLATEST}) {
42+
Write-Host "##[section]Skipping live test for PowerShell $curSimpleVer as it has already been explicitly specified in the pipeline." -ForegroundColor Green
43+
Write-Host "##vso[task.setvariable variable=skipLatest;isreadonly=true]true"
5844
}
5945
}
60-
61-
RemoveLiveTestPreInstalledModule -Name Az
62-
RemoveLiveTestPreInstalledModule -Name AzureRM
63-
InstallLiveTestDesiredPowerShell -DesiredVersion $DesiredVersion

tools/TestFx/Live/InstallLiveTestAzModules.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ switch ($Source) {
1818

1919
Install-Module -Name AzPreview -Repository $Source -Scope CurrentUser -AllowClobber -Force
2020

21-
Get-Module -Name Az
21+
Get-Module -Name AzPreview -ListAvailable
2222
Get-Module -Name Az.* -ListAvailable

0 commit comments

Comments
 (0)