Skip to content

Commit

Permalink
Use native methods for flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinGrote committed Dec 6, 2024
1 parent eebe650 commit 7ecdd5a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1030,12 +1030,19 @@ await PsesLanguageClient
});
}

[SkippableFact]
[Fact]
public async Task CanSendCompletionAndCompletionResolveRequestAsync()
{
Skip.If(IsLinux, "This depends on the help system, which is flaky on Linux.");
Skip.If(PsesStdioLanguageServerProcessHost.IsWindowsPowerShell, "This help system isn't updated in CI.");
string filePath = NewTestFile("Write-H");
await PsesLanguageClient
.SendRequest(
"evaluate",
new EvaluateRequestArguments
{
Expression = $"Update-Help Microsoft.Powershell.Utility -SourcePath {s_binDir};"
})
.ReturningVoid(CancellationToken.None);

string filePath = NewTestFile("Get-Date");

CompletionList completionItems = await PsesLanguageClient.TextDocument.RequestCompletion(
new CompletionParams
Expand All @@ -1048,28 +1055,28 @@ public async Task CanSendCompletionAndCompletionResolveRequestAsync()
});

CompletionItem completionItem = Assert.Single(completionItems,
completionItem1 => completionItem1.FilterText == "Write-Host");
completionItem1 => completionItem1.FilterText == "Get-Date");

CompletionItem updatedCompletionItem = await PsesLanguageClient
.SendRequest("completionItem/resolve", completionItem)
.Returning<CompletionItem>(CancellationToken.None);

Assert.Contains("Writes customized output to a host", updatedCompletionItem.Documentation.String);
Assert.Contains("Gets the current date and time.", updatedCompletionItem.Documentation.String);
}

[SkippableFact(Skip = "Completion for Expand-SlowArchive is flaky.")]
[Fact]
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"
})
.ReturningVoid(CancellationToken.None);

string filePath = NewTestFile("Expand-SlowArch");
string filePath = NewTestFile("Get-TestDate");

CompletionList completionItems = await PsesLanguageClient.TextDocument.RequestCompletion(
new CompletionParams
Expand All @@ -1078,17 +1085,15 @@ await PsesLanguageClient
{
Uri = DocumentUri.FromFileSystemPath(filePath)
},
Position = new Position(line: 0, character: 15)
Position = new Position(line: 0, character: 12)
});

CompletionItem completionItem = Assert.Single(completionItems,
completionItem1 => completionItem1.Label == "Expand-SlowArchive");
completionItem1 => completionItem1.Label == "Get-TestDate");

CompletionItem updatedCompletionItem = await PsesLanguageClient
.SendRequest("completionItem/resolve", completionItem)
.Returning<CompletionItem>(CancellationToken.None);
CompletionItem updatedCompletionItem = await PsesLanguageClient.ResolveCompletion(completionItem);

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

[SkippableFact]
Expand Down Expand Up @@ -1123,22 +1128,21 @@ public async Task CanSendSignatureHelpRequestAsync()
{
string filePath = NewTestFile("Get-Date -");

SignatureHelp signatureHelp = await PsesLanguageClient
.SendRequest(
"textDocument/signatureHelp",
new SignatureHelpParams
SignatureHelp signatureHelp = await PsesLanguageClient.RequestSignatureHelp
(
new SignatureHelpParams
{
TextDocument = new TextDocumentIdentifier
{
TextDocument = new TextDocumentIdentifier
{
Uri = new Uri(filePath)
},
Position = new Position
{
Line = 0,
Character = 10
}
})
.Returning<SignatureHelp>(CancellationToken.None);
Uri = new Uri(filePath)
},
Position = new Position
{
Line = 0,
Character = 10
}
}
);

Assert.Contains("Get-Date", signatureHelp.Signatures.First().Label);
}
Expand Down Expand Up @@ -1231,7 +1235,7 @@ await PsesLanguageClient
Assert.Equal(0, evaluateResponseBody.VariablesReference);
}

[Fact]
[Fact(Timeout = 60000)]
public async Task CanSendGetCommandRequestAsync()
{
List<object> pSCommandMessages =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />
<Import
Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
Expand All @@ -18,8 +19,10 @@
<Choose>
<When Condition=" '$(LocalOmniSharp)' == 'true' ">
<ItemGroup>
<ProjectReference Include="..\..\..\csharp-language-server-protocol\src\Client\Client.csproj" />
<ProjectReference Include="..\..\..\csharp-language-server-protocol\src\Dap.Client\Dap.client.csproj" />
<ProjectReference
Include="..\..\..\csharp-language-server-protocol\src\Client\Client.csproj" />
<ProjectReference
Include="..\..\..\csharp-language-server-protocol\src\Dap.Client\Dap.client.csproj" />
</ItemGroup>
</When>
<Otherwise>
Expand All @@ -37,4 +40,11 @@
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<!-- Used for Update-Help for some test fixtures -->
<Content Include="..\PowerShellEditorServices.Test.Shared\PSHelp\**\*"
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
5 changes: 3 additions & 2 deletions test/PowerShellEditorServices.Test.E2E/xunit.runner.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"appDomain": "denied",
"parallelizeTestCollections": true,
"parallelAlgorithm": "aggressive",
"parallelAlgorithm": "conservative",
"methodDisplay": "method",
"diagnosticMessages": true,
"longRunningTestSeconds": 60
"longRunningTestSeconds": 10,
"showLiveOutput": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<HelpInfo xmlns="http://schemas.microsoft.com/powershell/help/2010/05">
<HelpContentURI>https://aka.ms/powershell51-help</HelpContentURI>
<SupportedUICultures>
<UICulture>
<UICultureName>en-US</UICultureName>
<UICultureVersion>5.2.0.0</UICultureVersion>
</UICulture>
</SupportedUICultures>
</HelpInfo>
Binary file not shown.
1 change: 1 addition & 0 deletions test/PowerShellEditorServices.Test.Shared/PSHelp/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Windows PowerShell does not have updated help in CI by default and we utilize a private Azure Devops repo for builds that has no internet access. The completion tests validate the Windows Help so we update it offline from here so these tests can work.

0 comments on commit 7ecdd5a

Please sign in to comment.