Skip to content

Commit 2f49a79

Browse files
committed
Improve event waits in DebugAdapterTests
This change also adds a slight logging tweak to PowerShellContext to make the execution result more clear when the invocation state changes.
1 parent 3b6cd9c commit 2f49a79

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/PowerShellEditorServices/Session/PowerShellContext.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6+
using Microsoft.PowerShell.EditorServices.Console;
67
using Microsoft.PowerShell.EditorServices.Utility;
78
using Nito.AsyncEx;
89
using System;
@@ -17,9 +18,7 @@
1718

1819
namespace Microsoft.PowerShell.EditorServices
1920
{
20-
using Microsoft.PowerShell.EditorServices.Console;
2121
using System.Management.Automation;
22-
using System.Management.Automation.Host;
2322
using System.Management.Automation.Runspaces;
2423

2524
/// <summary>
@@ -567,9 +566,10 @@ private void OnSessionStateChanged(object sender, SessionStateChangedEventArgs e
567566
Logger.Write(
568567
LogLevel.Verbose,
569568
string.Format(
570-
"Session state changed --\r\n\r\n Old state: {0}\r\n New state: {1}",
569+
"Session state changed --\r\n\r\n Old state: {0}\r\n New state: {1}\r\n Result: {2}",
571570
this.SessionState.ToString(),
572-
e.NewSessionState.ToString()));
571+
e.NewSessionState.ToString(),
572+
e.ExecutionResult));
573573

574574
this.SessionState = e.NewSessionState;
575575

test/PowerShellEditorServices.Test.Host/DebugAdapterTests.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ await this.SendRequest(
7676

7777
// Abort script execution
7878
Task terminatedEvent = this.WaitForEvent(TerminatedEvent.Type);
79-
await this.SendRequest(DisconnectRequest.Type, new object());
80-
await terminatedEvent;
79+
await
80+
Task.WhenAll(
81+
this.SendRequest(DisconnectRequest.Type, new object()),
82+
terminatedEvent);
8183
}
8284

8385
[Fact]
@@ -93,8 +95,10 @@ public async Task DebugAdapterReceivesOutputEvents()
9395

9496
// Abort script execution
9597
Task terminatedEvent = this.WaitForEvent(TerminatedEvent.Type);
96-
await this.SendRequest(DisconnectRequest.Type, new object());
97-
await terminatedEvent;
98+
await
99+
Task.WhenAll(
100+
this.SendRequest(DisconnectRequest.Type, new object()),
101+
terminatedEvent);
98102
}
99103

100104
private Task LaunchScript(string scriptPath)

0 commit comments

Comments
 (0)