From 07df4dc96ed000c7b056e217a19a39799d69cd03 Mon Sep 17 00:00:00 2001 From: Azure PowerShell <65331932+azure-powershell-bot@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:58:57 +0800 Subject: [PATCH] Sync tools folder from main branch to generation branch (#25063) Co-authored-by: azurepowershell --- .azure-pipelines/sync-tools-folder.yml | 3 +-- .azure-pipelines/test-coverage.yml | 36 ++++++-------------------- tools/TestFx/EnvironmentSetupHelper.cs | 14 ++++++++-- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/.azure-pipelines/sync-tools-folder.yml b/.azure-pipelines/sync-tools-folder.yml index 78fa4e4edaf7..e74d313bf004 100644 --- a/.azure-pipelines/sync-tools-folder.yml +++ b/.azure-pipelines/sync-tools-folder.yml @@ -11,7 +11,6 @@ trigger: paths: include: - .azure-pipelines - - .github - tools - src/lib - .ci-config.json @@ -53,4 +52,4 @@ jobs: $BaseBranch = "$(BranchName)" $Description = "Migrate Sync tools code from main branch to $(BranchName) branch" ./tools/Github/CreatePR.ps1 -Title $Title -HeadBranch $HeadBranch -BaseBranch $BaseBranch -BotAccessToken $(GithubToken) -Description $Description - displayName: Create PR to $(BranchName) branch \ No newline at end of file + displayName: Create PR to $(BranchName) branch diff --git a/.azure-pipelines/test-coverage.yml b/.azure-pipelines/test-coverage.yml index d0eeda08db7e..efacfe9b5709 100644 --- a/.azure-pipelines/test-coverage.yml +++ b/.azure-pipelines/test-coverage.yml @@ -1,12 +1,8 @@ parameters: -- name: dotnet_sdk_6 - displayName: .NET 6 +- name: dotnet_sdk + displayName: .NET SDK type: string default: 6.0.x -- name: dotnet_sdk_7 - displayName: .NET 7 - type: string - default: 7.0.x - name: testFramework displayName: Test Framework type: string @@ -34,10 +30,10 @@ jobs: steps: - task: UseDotNet@2 - displayName: 'Install .NET 6 SDK' + displayName: 'Install .NET SDK' inputs: packageType: sdk - version: ${{ parameters.dotnet_sdk_6 }} + version: ${{ parameters.dotnet_sdk }} - task: DotNetCoreCLI@2 displayName: Build Azure PowerShell Modules @@ -61,10 +57,10 @@ jobs: steps: - task: UseDotNet@2 - displayName: 'Install .NET 6.0 SDK' + displayName: 'Install .NET SDK' inputs: packageType: sdk - version: ${{ parameters.dotnet_sdk_6 }} + version: ${{ parameters.dotnet_sdk }} - task: PowerShell@2 displayName: Initialize Environment @@ -88,7 +84,7 @@ jobs: arguments: 'build.proj -t:"Test" -p:"Configuration=Debug;TestFramework=${{ parameters.testFramework }}"' - task: PowerShell@2 - displayName: Test AutoRest-Based Cmdlets + displayName: Test Autorest-Based Cmdlets condition: succeeded() inputs: pwsh: true @@ -101,7 +97,7 @@ jobs: $debugDir = Join-Path -Path $rootDir -ChildPath "artifacts" | Join-Path -ChildPath "Debug" $env:PSModulePath += $delimiter + $debugDir Get-ChildItem -Path $debugDir -Filter test-module.ps1 -File -Recurse | Select-Object -ExpandProperty FullName | ForEach-Object { - Write-Host "##[section]Testing $_" + Write-Host "##[section]Executing $_" & $_ } @@ -114,22 +110,6 @@ jobs: filePath: ./tools/TestFx/Coverage/AnalyzeTestCoverage.ps1 arguments: -CalcBaseline - - template: util/get-keyvault-secret-steps.yml - parameters: - serviceConnectionName: $(AzureSubscription) - keyVaultName: $(KustoServicePrincipalKeyVaultName) - secretName: $(KustoServicePrincipalSecretName) - outVar: 'KustoServicePrincipalSecret' - - - task: PowerShell@2 - displayName: Save Test Coverage Results - condition: succeeded() - inputs: - pwsh: true - targetType: filePath - filePath: ./tools/TestFx/Coverage/SaveTestCoverageResult.ps1 - arguments: CITest $(KustoTenantId) $(KustoServicePrincipalId) $(KustoServicePrincipalSecret) $(KustoClusterName) $(KustoClusterRegion) - - template: util/get-github-pat-steps.yml - task: PowerShell@2 diff --git a/tools/TestFx/EnvironmentSetupHelper.cs b/tools/TestFx/EnvironmentSetupHelper.cs index f4f9497f5713..ddaefc911a0d 100644 --- a/tools/TestFx/EnvironmentSetupHelper.cs +++ b/tools/TestFx/EnvironmentSetupHelper.cs @@ -19,13 +19,13 @@ using Microsoft.Azure.Commands.ScenarioTest; using Microsoft.Azure.Commands.TestFx.Mocks; using Microsoft.Azure.ServiceManagement.Common.Models; -using Microsoft.Azure.Test.HttpRecorder; using Microsoft.Rest.ClientRuntime.Azure.TestFramework; using Microsoft.WindowsAzure.Commands.Common; using Microsoft.WindowsAzure.Commands.Utilities.Common; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.IO; using System.Linq; using System.Management.Automation; @@ -525,13 +525,23 @@ public virtual Collection RunPowerShellTest(params string[] scripts) Collection output = null; foreach (var script in scripts) { - Console.WriteLine($"Executing test: {script}"); TracingInterceptor?.Information(script); powershell.AddScript(script); } + try { + string testName = string.Join("+", scripts); + Console.WriteLine($"Executing test {testName}"); + + var watch = Stopwatch.StartNew(); output = powershell.Invoke(); + watch.Stop(); + + var resultFormatting = watch.ElapsedMilliseconds < 5000 ? "##[section]" : "##[warning]"; + + Console.WriteLine($"{resultFormatting}Test {testName} completed in {watch.ElapsedMilliseconds}ms"); + if (powershell.Streams.Error.Count > 0) { throw new RuntimeException($"Test failed due to a non-empty error stream. First error: {PowerShellExtensions.FormatErrorRecord(powershell.Streams.Error[0])}{(powershell.Streams.Error.Count > 0 ? "Check the error stream in the test log for additional errors." : "")}");