Skip to content
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

Improve E2E Test Fixtures to be less flaky #2208

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ jobs:
shell: pwsh
run: ./pwsh/tools/install-powershell.ps1 -Daily

- name: If Debugging, start upterm for interactive pipeline troubleshooting
if: ${{ runner.debug == 1 }}
uses: lhotari/action-upterm@v1
with:
wait-timeout-minutes: 1

- name: Build and test
shell: pwsh
run: Invoke-Build -Configuration Release ${{ github.event_name == 'merge_group' && 'TestFull' || 'Test' }}
Expand Down
84 changes: 82 additions & 2 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,88 @@ Task BuildCmdletHelp -After AssembleModule {
}

Task SetupHelpForTests {
Write-Build DarkMagenta 'Updating help (for tests)'
Update-Help -Module Microsoft.PowerShell.Management, Microsoft.PowerShell.Utility -Force -Scope CurrentUser -UICulture en-US
# Some CI do not ship with help included, and the secure devops pipeline also does not allow internet access, so we must update help from our local repository source.

# Only commands in Microsoft.PowerShell.Archive can be tested for help so as to minimize the repository storage.
# This requires admin rights for PS5.1

#NOTE: You can run this task once as admin or update help separately, and continue to run tests as non-admin, if for instance developing locally.

$installHelpScript = {
param(
[Parameter(Position = 0)][string]$helpPath
)
$PSVersion = $PSVersionTable.PSVersion
$ErrorActionPreference = 'Stop'
$helpPath = Resolve-Path $helpPath
if ($PSEdition -ne 'Desktop') {
$helpPath = Join-Path $helpPath '7'
}

if ((Get-Help Expand-Archive).remarks -notlike 'Get-Help cannot find the Help files*') {
Write-Host -Fore Green "PowerShell $PSVersion Archive Help is already installed"
return
}

if ($PSEdition -eq 'Desktop') {
# Cant use requires RunAsAdministrator because PS isn't smart enough to know this is a subscript.
if (-not [Security.Principal.WindowsPrincipal]::new(
[Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator
)) {
throw 'Windows PowerShell Update-Help requires admin rights. Please re-run the script in an elevated powershell session.'
}
}

Write-Host -Fore Magenta "Powershell $PSVersion Archive Help is not installed, installing from $helpPath"

$updateHelpParams = @{
Module = 'Microsoft.PowerShell.Archive'
SourcePath = $helpPath
UICulture = 'en-US'
Force = $true
Verbose = $true
}

#PS7+ does not require admin rights if currentuser is used for scope. 5.1 does not have this option.
if ($PSEdition -ne 'Desktop') {
$updateHelpParams.'Scope' = 'CurrentUser'
}
#Update the help, and capture verbose output
$updateHelpOutput = Update-Help @updateHelpParams *>&1

if ((Get-Help Expand-Archive).remarks -like 'Get-Help cannot find the Help files*') {
throw "Failed to install PowerShell $PSVersion Help: $updateHelpOutput"
} else {
Write-Host -Fore Green "Powershell $PSVersion Archive Help installed successfully"
}
}

#Need this to inject the help file path, since PSScriptRoot won't work inside the script
$helpPath = Resolve-Path "$PSScriptRoot\test\PowerShellEditorServices.Test.Shared\PSHelp" -ErrorAction Stop
Write-Host -Fore Magenta "Runner Help located at $helpPath"

if (Get-Command powershell.exe -CommandType Application -ea 0) {
Write-Host -Fore Magenta 'Checking PowerShell 5.1 help'
& powershell.exe -NoProfile -NonInteractive -Command $installHelpScript -args $helpPath
if ($LASTEXITCODE -ne 0) {
throw 'Failed to install PowerShell 5.1 Help.'
}
}

if ($PwshDaily -and (Get-Command $PwshDaily -ea 0)) {
Write-Host -Fore Magenta "Checking PWSH Daily help at $PwshDaily"
Invoke-BuildExec { & $PwshDaily -NoProfile -NonInteractive -Command $installHelpScript -args $helpPath }
if ($LASTEXITCODE -ne 0) {
throw 'Failed to install PowerShell Daily Help.'
}
}

if ($PSEdition -eq 'Core') {
Write-Host -Fore Magenta 'Checking Runner Pwsh help'
& $installHelpScript $helpPath
}
}

Task TestPS74 Build, SetupHelpForTests, {
Expand Down
3 changes: 2 additions & 1 deletion src/PowerShellEditorServices/Server/PsesDebugServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public async Task StartAsync()
response.SupportsDelayedStackTraceLoading = true;

return Task.CompletedTask;
});
})
;
}).ConfigureAwait(false);
}

Expand Down
Loading