Skip to content

Commit f80abdc

Browse files
authored
Merge pull request #361 from PowerShell/daviwil/test-fixes
Clean up CI tests and build output
2 parents 9b617e8 + b464552 commit f80abdc

File tree

12 files changed

+84
-67
lines changed

12 files changed

+84
-67
lines changed

PowerShellEditorServices.build.ps1

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,39 @@ task Build {
144144
exec { & $script:dotnetExe build -c $Configuration .\PowerShellEditorServices.sln $script:TargetFrameworksParam }
145145
}
146146

147+
function UploadTestLogs {
148+
if ($script:IsCIBuild) {
149+
$testLogsPath = "$PSScriptRoot/test/PowerShellEditorServices.Test.Host/bin/$Configuration/net451/logs"
150+
$testLogsZipPath = "$PSScriptRoot/TestLogs.zip"
151+
152+
if (Test-Path $testLogsPath) {
153+
[System.IO.Compression.ZipFile]::CreateFromDirectory(
154+
$testLogsPath,
155+
$testLogsZipPath)
156+
157+
Push-AppveyorArtifact $testLogsZipPath
158+
}
159+
else {
160+
Write-Host "`n### WARNING: Test logs could not be found!`n" -ForegroundColor Yellow
161+
}
162+
}
163+
}
164+
147165
task Test -If { !$script:IsUnix } {
148166
exec { & $script:dotnetExe test -c $Configuration -f net451 .\test\PowerShellEditorServices.Test\PowerShellEditorServices.Test.csproj }
149167
exec { & $script:dotnetExe test -c $Configuration -f net451 .\test\PowerShellEditorServices.Test.Protocol\PowerShellEditorServices.Test.Protocol.csproj }
150168
exec { & $script:dotnetExe test -c $Configuration -f net451 .\test\PowerShellEditorServices.Test.Host\PowerShellEditorServices.Test.Host.csproj }
151169
}
152170

171+
task CITest (job Test -Safe), {
172+
# This task is used to ensure we have a chance to upload
173+
# test logs as a CI artifact when the tests fail
174+
if (error Test) {
175+
UploadTestLogs
176+
Write-Error "Failing build due to test failure."
177+
}
178+
}
179+
153180
task LayoutModule -After Build, BuildHost {
154181
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\ -Type Directory | Out-Null
155182
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop -Type Directory | Out-Null
@@ -185,21 +212,5 @@ task UploadArtifacts -If ($script:IsCIBuild) {
185212
}
186213
}
187214

188-
task UploadTestLogs -After Test -If ($script:IsCIBuild) {
189-
$testLogsPath = "$PSScriptRoot/test/PowerShellEditorServices.Test.Host/bin/$Configuration/net451/logs"
190-
$testLogsZipPath = "$PSScriptRoot/TestLogs.zip"
191-
192-
if (Test-Path $testLogsPath) {
193-
[System.IO.Compression.ZipFile]::CreateFromDirectory(
194-
$testLogsPath,
195-
$testLogsZipPath)
196-
197-
Push-AppveyorArtifact $testLogsZipPath
198-
}
199-
else {
200-
Write-Host "`n### WARNING: Test logs could not be found!`n" -ForegroundColor Yellow
201-
}
202-
}
203-
204215
# The default task is to run the entire CI build
205-
task . GetProductVersion, Clean, Build, TestPowerShellApi, Test, PackageNuGet, PackageModule, UploadArtifacts
216+
task . GetProductVersion, Clean, Build, TestPowerShellApi, CITest, PackageNuGet, PackageModule, UploadArtifacts

src/PowerShellEditorServices.Protocol/MessageProtocol/Channel/NamedPipeClientChannel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.Channel
1212
public class NamedPipeClientChannel : ChannelBase
1313
{
1414
private string pipeName;
15-
private bool isClientConnected;
1615
private NamedPipeClientStream pipeClient;
1716

1817
public NamedPipeClientChannel(string pipeName)

src/PowerShellEditorServices.Protocol/MessageProtocol/MessageDispatcher.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class MessageDispatcher
1818
#region Fields
1919

2020
private ChannelBase protocolChannel;
21-
private AsyncQueue<Message> messagesToWrite;
2221
private AsyncContextThread messageLoopThread;
2322

2423
private Dictionary<string, Func<Message, MessageWriter, Task>> requestHandlers =

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected Task LaunchScript(RequestContext<object> requestContext)
9191
// Make sure remaining output is flushed before exiting
9292
await this.outputDebouncer.Flush();
9393

94-
await requestContext.SendEvent(
94+
await this.SendEvent(
9595
TerminatedEvent.Type,
9696
new TerminatedEvent());
9797

@@ -122,10 +122,19 @@ protected async Task HandleConfigurationDoneRequest(
122122
{
123123
if (!string.IsNullOrEmpty(this.scriptPathToLaunch))
124124
{
125-
// Configuration is done, launch the script
126-
var nonAwaitedTask =
127-
this.LaunchScript(requestContext)
128-
.ConfigureAwait(false);
125+
if (this.editorSession.PowerShellContext.SessionState == PowerShellContextState.Ready)
126+
{
127+
// Configuration is done, launch the script
128+
var nonAwaitedTask =
129+
this.LaunchScript(requestContext)
130+
.ConfigureAwait(false);
131+
}
132+
else
133+
{
134+
Logger.Write(
135+
LogLevel.Verbose,
136+
"configurationDone request called after script was already launched, skipping it.");
137+
}
129138
}
130139

131140
await requestContext.SendResult(null);
@@ -141,7 +150,9 @@ protected async Task HandleLaunchRequest(
141150
string workingDir =
142151
launchParams.Cwd ??
143152
launchParams.Script ??
153+
#pragma warning disable 618
144154
launchParams.Program;
155+
#pragma warning restore 618
145156

146157
if (workingDir != null)
147158
{
@@ -183,7 +194,9 @@ protected async Task HandleLaunchRequest(
183194

184195
// Store the launch parameters so that they can be used later
185196
this.noDebug = launchParams.NoDebug;
197+
#pragma warning disable 618
186198
this.scriptPathToLaunch = launchParams.Script ?? launchParams.Program;
199+
#pragma warning restore 618
187200
this.arguments = arguments;
188201

189202
await requestContext.SendResult(null);
@@ -198,7 +211,7 @@ await this.editorSession.PowerShellContext.ExecuteScriptString(
198211

199212
// Send the InitializedEvent so that the debugger will continue
200213
// sending configuration requests
201-
await requestContext.SendEvent(
214+
await this.SendEvent(
202215
InitializedEvent.Type,
203216
null);
204217
}
@@ -315,9 +328,6 @@ protected async Task HandleDisconnectRequest(
315328
{
316329
await requestContext.SendResult(null);
317330
this.editorSession.PowerShellContext.SessionStateChanged -= handler;
318-
319-
// Stop the server
320-
await this.Stop();
321331
}
322332
};
323333

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Microsoft.PowerShell.EditorServices.Utility;
1313
using Newtonsoft.Json.Linq;
1414
using System;
15-
using System.Collections;
1615
using System.Collections.Generic;
1716
using System.IO;
1817
using System.Linq;
@@ -232,7 +231,7 @@ private async Task HandleSetPSSARulesRequest(
232231
await RunScriptDiagnostics(
233232
new ScriptFile[] { scripFile },
234233
editorSession,
235-
requestContext.SendEvent);
234+
this.SendEvent);
236235
await sendresult;
237236
}
238237

@@ -1136,7 +1135,7 @@ private Task RunScriptDiagnostics(
11361135
EditorSession editorSession,
11371136
EventContext eventContext)
11381137
{
1139-
return RunScriptDiagnostics(filesToAnalyze, editorSession, eventContext.SendEvent);
1138+
return RunScriptDiagnostics(filesToAnalyze, editorSession, this.SendEvent);
11401139
}
11411140

11421141
private Task RunScriptDiagnostics(

src/PowerShellEditorServices.Protocol/Server/LanguageServerBase.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server
1212
{
1313
public abstract class LanguageServerBase : ProtocolEndpoint
1414
{
15-
private bool isStarted;
1615
private ChannelBase serverChannel;
17-
private TaskCompletionSource<bool> serverExitedTask;
1816

1917
public LanguageServerBase(ChannelBase serverChannel) :
2018
base(serverChannel, MessageProtocolType.LanguageServer)
@@ -72,12 +70,6 @@ private async Task HandleExitNotification(
7270
{
7371
// Stop the server channel
7472
await this.Stop();
75-
76-
// Notify any waiter that the server has exited
77-
if (this.serverExitedTask != null)
78-
{
79-
this.serverExitedTask.SetResult(true);
80-
}
8173
}
8274
}
8375
}

src/PowerShellEditorServices/PowerShellEditorServices.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@
2828
</PropertyGroup>
2929

3030
<!-- Fail the release build if there are missing public API documentation comments -->
31-
<!-- TODO #353: Re-enable this once dotnet doesn't hang on these errors anymore -->
32-
<!--<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
31+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
3332
<WarningsAsErrors>1591,1573,1572</WarningsAsErrors>
3433
<DocumentationFile>bin\$(TargetFramework)\$(Configuration)\Microsoft.PowerShell.EditorServices.xml</DocumentationFile>
35-
</PropertyGroup>-->
34+
</PropertyGroup>
3635

3736
<Target Name="PowerShellVersionOutput" BeforeTargets="Compile">
3837
<Message

src/PowerShellEditorServices/Session/PowerShellContext.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,13 +706,16 @@ public void AbortExecution()
706706
{
707707
Logger.Write(LogLevel.Verbose, "Execution abort requested...");
708708

709-
this.powerShell.BeginStop(null, null);
710-
this.SessionState = PowerShellContextState.Aborting;
711-
712709
if (this.IsDebuggerStopped)
713710
{
714711
this.ResumeDebugger(DebuggerResumeAction.Stop);
715712
}
713+
else
714+
{
715+
this.powerShell.BeginStop(null, null);
716+
}
717+
718+
this.SessionState = PowerShellContextState.Aborting;
716719
}
717720
else
718721
{
@@ -1114,7 +1117,6 @@ private static SessionStateChangedEventArgs TranslateInvocationStateInfo(PSInvoc
11141117
break;
11151118

11161119
case PSInvocationState.Stopping:
1117-
// TODO: Collapse this so that the result shows that execution was aborted
11181120
newState = PowerShellContextState.Aborting;
11191121
break;
11201122

test/PowerShellEditorServices.Test.Host/DebugAdapterTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public async Task DebugAdapterReceivesOutputEvents()
122122
private async Task LaunchScript(string scriptPath)
123123
{
124124
await this.debugAdapterClient.LaunchScript(scriptPath);
125-
await this.SendRequest(ConfigurationDoneRequest.Type, null);
126125
}
127126
}
128127
}

test/PowerShellEditorServices.Test.Host/LanguageServerTests.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,22 @@ await this.SendRequest(
168168
[Fact(Skip = "Skipped until variable documentation gathering is added back.")]
169169
public async Task CompletesDetailOnVariableDocSuggestion()
170170
{
171-
//await this.SendOpenFileEvent("TestFiles\\CompleteFunctionName.ps1");
171+
await this.SendOpenFileEvent("TestFiles\\CompleteFunctionName.ps1");
172172

173-
//await this.SendRequest(
174-
// CompletionRequest.Type,
175-
// new TextDocumentPosition
176-
// {
177-
// Uri = "TestFiles\\CompleteFunctionName.ps1",
178-
// Position = new Position
179-
// {
180-
// Line = 7,
181-
// Character = 5
182-
// }
183-
// });
173+
await this.SendRequest(
174+
CompletionRequest.Type,
175+
new TextDocumentPosition
176+
{
177+
Uri = "TestFiles\\CompleteFunctionName.ps1",
178+
Position = new Position
179+
{
180+
Line = 7,
181+
Character = 5
182+
}
183+
});
184+
185+
// TODO: This section needs to be updated, seems that
186+
// CompletionsResponse is missing.
184187

185188
//CompletionsResponse completion = this.WaitForMessage<CompletionsResponse>();
186189
//List<string> entryName = new List<string>();

0 commit comments

Comments
 (0)