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

Conversation

JustinGrote
Copy link
Collaborator

@JustinGrote JustinGrote commented Dec 5, 2024

  • Rewrite Pses Stdio host to be task-based and interface-based
  • Replace LoggingStream with DebugOutputStream to log LSP communication to debug console when debugging tests
  • Fix up Tests that require help by offline updating help in all platforms/CI

- [ ] Wire up LSP Client logging to XUnit ITestOutputHelper
- [ ] Wire up PSES Initial File Logging to debug console

@JustinGrote JustinGrote self-assigned this Dec 5, 2024
@JustinGrote JustinGrote changed the title Initial Pass that implements DebugAdapterServerTestBase Improve E2E Test Fixtures to be less flaky Dec 5, 2024
@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch 3 times, most recently from 5cb7349 to 1d8a574 Compare December 5, 2024 06:47
@JustinGrote
Copy link
Collaborator Author

@andyleejordan @SeeminglyScience Did a lot of cleanup here, DAP tests run much faster and I should have cleaned up the race conditions, they've been completely reliable for me so far. The tests should also read fairly cleaner now as well.

@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch from 7f0083c to 7ecdd5a Compare December 6, 2024 17:46
@andyleejordan
Copy link
Member

@JustinGrote running this through the internal pipeline right now!

@andyleejordan
Copy link
Member

@JustinGrote running this through the internal pipeline right now!

Sooo actually per 20fa478 we cannot currently run the tests on OneBranch since it's stuck with PowerShell 7.3...so this will have to wait until January 😵

@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch from 7ecdd5a to b1bafa3 Compare December 20, 2024 19:32
@andyleejordan
Copy link
Member

Hi @JustinGrote, we can finally run the tests again in ADO. Would you want to get this PR updated? Note that I had to skip the getCommand test, it just hung (@SeeminglyScience's guess was that the ADO PowerShell might have network shares in PSModulePath but yeah it just ran for twenty minutes before I killed it).

@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch from b1bafa3 to b5c00a3 Compare February 28, 2025 00:26
@JustinGrote
Copy link
Collaborator Author

@andyleejordan rebased and passed locally for me. Lets see if ADO likes it.
image

@JustinGrote
Copy link
Collaborator Author

Looks like it works. I can do the logging fixups as a separate item especially now that the other logging stuff was implemented.

@JustinGrote JustinGrote marked this pull request as ready for review February 28, 2025 00:48
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR improves the stability and clarity of the E2E test fixtures by reworking the PSES process host to use task- and interface-based patterns and by replacing the legacy LoggingStream with DebugOutputStream for logging LSP communication.

  • Converted the StdioLanguageServerProcessHost and related test fixtures to use updated process management with task completion sources.
  • Replaced LoggingStream with DebugOutputStream to log stream activity only when a debugger is attached.
  • Updated references in tests and LSP fixtures to use the new host implementation.

Reviewed Changes

File Description
test/PowerShellEditorServices.Test.E2E/Hosts/StdioLanguageServerProcessHost.cs Refactored host start/stop logic to use task-based state tracking.
test/PowerShellEditorServices.Test.E2E/Hosts/PsesStdioLanguageServerProcessHost.cs Updated host constructor and environment variable references for improved test stability.
test/PowerShellEditorServices.Test.E2E/Hosts/DebugOutputStream.cs Introduced DebugOutputStream to log read/write operations when debugging tests.
test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs Updated tests to use the new host and logging methods; removed dependency on LoggingStream.
test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs, LSPTestsFixtures.cs, IDebugAdapterClientExtensions.cs Updated usage and references from the legacy process host to the new one.
Various Process files Removed legacy PsesStdioProcess and related files to consolidate host management.
src/PowerShellEditorServices/Server/PsesDebugServer.cs Minor formatting adjustment in the debug server response initialization.

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch from e12f94b to 5642221 Compare February 28, 2025 00:55
Copy link
Member

@andyleejordan andyleejordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like this a lot, just some questions. Also as far as ADO goes at this point we just have to YOLO it. I can't easily test a PR against the pipeline that would actually block us from releasing if it broke. 🤷 (Long story, really annoying.)


<ItemGroup>
<!-- Used for Update-Help for some test fixtures -->
<Content Include="..\PowerShellEditorServices.Test.Shared\PSHelp\**\*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this fix all the tests that depend on help, and could we remove the build step where we Update-Help for the tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if the tests use Microsoft.PowerShell.Utility cmdlets for their reference. This is only required for Windows PowerShell since it doesn't ship this help in-box, all pwsh flavors do ship help in-box and so we don't have to do this. Assuming we find/adjust all help-based tests to use Microsoft.PowerShell.Utility, then yes this should fix them in AzDO CI

@@ -1177,7 +1181,7 @@ await PsesLanguageClient
[SkippableFact]
public async Task CanSendGetCommentHelpRequestAsync()
{
Skip.If(PsesStdioProcess.RunningInConstrainedLanguageMode && PsesStdioProcess.IsWindowsPowerShell,
Skip.If(PsesStdioLanguageServerProcessHost.RunningInConstrainedLanguageMode && PsesStdioLanguageServerProcessHost.IsWindowsPowerShell,
"Windows PowerShell doesn't trust PSScriptAnalyzer by default so it won't load.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, is this why people are having problems with the formatter "hanging" when they use Windows PowerShell? Food for thought...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be! Maybe I can get some LSP trace logs from them and stick in some telemetry to find out.


Assert.Contains("Extracts files from a specified archive", updatedCompletionItem.Documentation.String);
Assert.Contains("Gets the current date and time.", updatedCompletionItem.Documentation.String);
}

[SkippableFact]
public async Task CanSendHoverRequestAsync()
{
Skip.If(IsLinux, "This depends on the help system, which is flaky on Linux.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to skip this test now that the help is mocked?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not? As you said lets YOLO it as a test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think I separately fixed this test in the other branch so there might be a conflict, I'll rebase.

public async Task CanSendCompletionResolveWithModulePrefixRequestAsync()
{
await PsesLanguageClient
.SendRequest(
"evaluate",
new EvaluateRequestArguments
{
Expression = "Import-Module Microsoft.PowerShell.Archive -Prefix Slow"
Expression = $"Update-Help Microsoft.Powershell.Utility -SourcePath {s_binDir};Import-Module Microsoft.PowerShell.Utility -Prefix Test -Force"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh sweet, ok yeah, I think there's an Update-Help in the build script too...

s_binDir, $"pses_test_logs_{Path.GetRandomFileName()}");

private const string s_logLevel = "Diagnostic";
private static readonly string[] s_featureFlags = { "PSReadLine" };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really pass this through in feature flags still? I didn't think we had anything in feature flags.

Copy link
Collaborator Author

@JustinGrote JustinGrote Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just looked and I didn't see this feature flag actually referenced anywhere, so it can probably be removed but I think that should be the scope of another PR. You're probably seeing it here as a "change" because I moved the file to a new folder I belieeve.

@andyleejordan andyleejordan force-pushed the test/DapE2ETestUpdates branch from 5642221 to 4e68bf6 Compare March 4, 2025 19:28
@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch from 4e68bf6 to 52feb6c Compare March 4, 2025 21:52
@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch from e0e8c1e to a476e9f Compare March 4, 2025 22:13
@JustinGrote JustinGrote marked this pull request as draft March 5, 2025 03:03
@JustinGrote
Copy link
Collaborator Author

@andyleejordan the FindSymbolsInDSCFile test failure appears to be because of 0135baa #1984. You updated the IDs of DSC symbols to include a prefix, but the test doesn't check for that new prefix.

"configuration " + name + " { }",
nameExtent,

I will "fix" this test but please confirm if you're expecting something else. Also, completions allow for a sortText property in the LSP, maybe we should implement this more explicitly if that's the intention for the prefix?

JustinGrote added a commit that referenced this pull request Mar 5, 2025
Contengent assuming #2208 (comment) is OK from @andyleejordan
Contengent assuming #2208 (comment) is OK from @andyleejordan
@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch from 69ef1bd to 2d7d3e2 Compare March 5, 2025 23:42
@JustinGrote
Copy link
Collaborator Author

@andyleejordan I came up with a better way to do the "offline" help update in eaeefa1 and centralized it in the build script again.

@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch 5 times, most recently from 22993ea to 34347ba Compare March 6, 2025 03:01
@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch from 34347ba to b22510a Compare March 6, 2025 03:07
@andyleejordan
Copy link
Member

@andyleejordan the FindSymbolsInDSCFile test failure appears to be because of 0135baa #1984. You updated the IDs of DSC symbols to include a prefix, but the test doesn't check for that new prefix.

"configuration " + name + " { }",
nameExtent,

I will "fix" this test but please confirm if you're expecting something else. Also, completions allow for a sortText property in the LSP, maybe we should implement this more explicitly if that's the intention for the prefix?

Oops. I don't think I'm expecting something else. And if I remember correctly on the sortText, VS Code completely ignored it and applies their own sorting.

@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch 2 times, most recently from 3eb0adb to 50a806f Compare March 6, 2025 20:41
@JustinGrote JustinGrote force-pushed the test/DapE2ETestUpdates branch from 50a806f to 2a65e3d Compare March 6, 2025 20:58
@JustinGrote JustinGrote marked this pull request as ready for review March 6, 2025 21:12
@JustinGrote JustinGrote requested a review from a team as a code owner March 6, 2025 21:12
@JustinGrote
Copy link
Collaborator Author

JustinGrote commented Mar 6, 2025

@andyleejordan this should be ready for re-review and an internal pipeline test. Changes summary:

  1. Fixed help-based tests to all use Microsoft.PowerShell.Archive, because it has a small help file to be vendored into the codebase
  2. Added update help build script for all pwsh platforms with verify check.
  3. Added upterm to the CI process pre-build. This allows, if you explicitly re-run a job with debug build, to be able to SSH into the runner to interactively troubleshoot/debug issues. Only runs on debug re-runs
  4. Most tests conditional on platforms fixed or mitigated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants