From ece47e9aba8779c572f1e2074e7e184984808d41 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 22 Jul 2022 08:39:05 -0700 Subject: [PATCH 1/5] Dispose `_psesProcess` in DAP tests --- .../DebugAdapterProtocolMessageTests.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs b/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs index ab99aa6eb..a091d5cd2 100644 --- a/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs +++ b/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; @@ -19,7 +19,7 @@ namespace PowerShellEditorServices.Test.E2E { [Trait("Category", "DAP")] - public class DebugAdapterProtocolMessageTests : IAsyncLifetime + public class DebugAdapterProtocolMessageTests : IAsyncLifetime, IDisposable { private const string TestOutputFileName = "__dapTestOutputFile.txt"; private static readonly bool s_isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); @@ -104,7 +104,13 @@ await PsesDebugAdapterClient.RequestDisconnect(new DisconnectArguments TerminateDebuggee = true }).ConfigureAwait(true); await _psesProcess.Stop().ConfigureAwait(true); + } + + public void Dispose() + { + GC.SuppressFinalize(this); PsesDebugAdapterClient?.Dispose(); + _psesProcess?.Dispose(); } private static string NewTestFile(string script, bool isPester = false) From 7e302871db5a042755060f1c7613a584db8b8729 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 22 Jul 2022 08:39:42 -0700 Subject: [PATCH 2/5] Use double instead of single quotes in DAP tests So we can interpolate variables. --- .../DebugAdapterProtocolMessageTests.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs b/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs index a091d5cd2..9052e2bde 100644 --- a/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs +++ b/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; @@ -136,11 +136,23 @@ private string GenerateScriptFromLoggingStatements(params string[] logStatements } // Have script create file first with `>` (but don't rely on overwriting). - StringBuilder builder = new StringBuilder().Append('\'').Append(logStatements[0]).Append("' > '").Append(s_testOutputPath).AppendLine("'"); + // NOTE: We uses double quotes so that we can use PowerShell variables. + StringBuilder builder = new StringBuilder() + .Append("Write-Output \"") + .Append(logStatements[0]) + .Append("\" > '") + .Append(s_testOutputPath) + .AppendLine("'"); + for (int i = 1; i < logStatements.Length; i++) { // Then append to that script with `>>`. - builder.Append('\'').Append(logStatements[i]).Append("' >> '").Append(s_testOutputPath).AppendLine("'"); + builder + .Append("Write-Output \"") + .Append(logStatements[i]) + .Append("\" >> '") + .Append(s_testOutputPath) + .AppendLine("'"); } _output.WriteLine("Script is:"); From dcd9d8f1c9eba29e7b7a508640c0ecc90b6be494 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 22 Jul 2022 08:41:56 -0700 Subject: [PATCH 3/5] Add 10s timeout to DAP tests Since this logic will spin forever if a test fails. --- .../DebugAdapterProtocolMessageTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs b/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs index 9052e2bde..19fe31cd1 100644 --- a/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs +++ b/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs @@ -162,7 +162,7 @@ private string GenerateScriptFromLoggingStatements(params string[] logStatements private static async Task GetLog() { - while (!File.Exists(s_testOutputPath)) + for (int i = 0; !File.Exists(s_testOutputPath) && i < 10; i++) { await Task.Delay(1000).ConfigureAwait(true); } From 402ab4f5056d8ae6b8f2a96cb24dc928c03f54a2 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 21 Jul 2022 12:44:59 -0700 Subject: [PATCH 4/5] Add regression test for debugging script with dot-source operator --- .../DebugAdapterProtocolMessageTests.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs b/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs index 19fe31cd1..b2e841310 100644 --- a/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs +++ b/test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs @@ -182,6 +182,17 @@ public void CanInitializeWithCorrectServerSettings() Assert.True(PsesDebugAdapterClient.ServerSettings.SupportsSetVariable); } + [Fact] + public async Task UsesDotSourceOperatorAndQuotesAsync() + { + string filePath = NewTestFile(GenerateScriptFromLoggingStatements("$($MyInvocation.Line)")); + await PsesDebugAdapterClient.LaunchScript(filePath, Started).ConfigureAwait(true); + ConfigurationDoneResponse configDoneResponse = await PsesDebugAdapterClient.RequestConfigurationDone(new ConfigurationDoneArguments()).ConfigureAwait(true); + Assert.NotNull(configDoneResponse); + Assert.Collection(await GetLog().ConfigureAwait(true), + (i) => Assert.StartsWith(". \"", i)); + } + [Fact] public async Task CanLaunchScriptWithNoBreakpointsAsync() { From 0759d9d4fdc9be5081327cbbea5c9adfc9e76aa4 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 22 Jul 2022 09:00:13 -0700 Subject: [PATCH 5/5] Revert "Skip flaky test on Linux" and use timeout instead This reverts commit 49500fa48b9502595641f654a3bf63bd4b5d9901. Something weird is going on with the Ubuntu CI where some of these tests hang, needs more investigation. --- .../Debugging/DebugServiceTests.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs index 02adda0d3..26214bff1 100644 --- a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs @@ -103,7 +103,8 @@ private Task ExecutePowerShellCommand(string command, params string[] args) private void AssertDebuggerPaused() { - DebuggerStoppedEventArgs eventArgs = debuggerStoppedQueue.Take(CancellationToken.None); + using CancellationTokenSource cts = new(10000); + DebuggerStoppedEventArgs eventArgs = debuggerStoppedQueue.Take(cts.Token); Assert.Empty(eventArgs.OriginalEvent.Breakpoints); } @@ -112,7 +113,8 @@ private void AssertDebuggerStopped( int lineNumber = -1, CommandBreakpointDetails commandBreakpointDetails = default) { - DebuggerStoppedEventArgs eventArgs = debuggerStoppedQueue.Take(CancellationToken.None); + using CancellationTokenSource cts = new(10000); + DebuggerStoppedEventArgs eventArgs = debuggerStoppedQueue.Take(cts.Token); Assert.True(psesHost.DebugContext.IsStopped); @@ -587,10 +589,9 @@ await debugService.SetLineBreakpointsAsync( Assert.Equal("$false", falseVar.ValueString); } - [SkippableFact] + [Fact] public async Task DebuggerSetsVariablesNoConversion() { - Skip.If(VersionUtils.IsLinux, "Test hangs on Linux for some reason"); await debugService.SetLineBreakpointsAsync( variableScriptFile, new[] { BreakpointDetails.Create(variableScriptFile.FilePath, 14) }).ConfigureAwait(true);