Skip to content

Commit 93548af

Browse files
committed
WIP: Threading fixes
1 parent d06467c commit 93548af

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ public void TriggerShutdown()
245245
if (Interlocked.Exchange(ref _shuttingDown, 1) == 0)
246246
{
247247
_cancellationContext.CancelCurrentTaskStack();
248+
_pipelineThread.Join();
248249
}
249250
}
250251

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ public void Dispose()
5959
{
6060
debugService.Abort();
6161
_psesHost.StopAsync().GetAwaiter().GetResult();
62-
GC.SuppressFinalize(this);
6362
}
6463

6564
private void DebugService_DebuggerStopped(object sender, DebuggerStoppedEventArgs e)
6665
{
67-
_ = Task.Run(() => debuggerStoppedQueue.Add(e));
66+
debuggerStoppedQueue.Add(e);
6867
}
6968

7069
private ScriptFile GetDebugScript(string fileName)
@@ -477,13 +476,14 @@ await debugService.SetLineBreakpointsAsync(
477476
}
478477

479478
[Trait("Category", "DebugService")]
480-
[Fact(Skip = "This test has a race condition.")]
479+
[Fact]
481480
public async Task DebuggerBreaksWhenRequested()
482481
{
483482
var confirmedBreakpoints = await GetConfirmedBreakpoints(debugScriptFile).ConfigureAwait(false);
484483
Assert.Equal(0, confirmedBreakpoints.Count);
485484
Task _ = ExecuteDebugFile();
486-
debugService.Break();
485+
// NOTE: This must be run on a separate thread so the async event handlers can fire.
486+
await Task.Run(() => debugService.Break()).ConfigureAwait(false);
487487
AssertDebuggerPaused();
488488
}
489489

@@ -492,7 +492,8 @@ public async Task DebuggerBreaksWhenRequested()
492492
public async Task DebuggerRunsCommandsWhileStopped()
493493
{
494494
Task _ = ExecuteDebugFile();
495-
debugService.Break();
495+
// NOTE: This must be run on a separate thread so the async event handlers can fire.
496+
await Task.Run(() => debugService.Break()).ConfigureAwait(false);
496497
AssertDebuggerPaused();
497498

498499
// Try running a command from outside the pipeline thread

0 commit comments

Comments
 (0)