Skip to content

Commit a1aa699

Browse files
committed
Set ServerStarted with TrySetResult since unit tests might do it twice
1 parent 1f809c9 commit a1aa699

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/DebugEventHandlerService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private void OnRunspaceChanged(object sender, RunspaceChangedEventArgs e)
101101
// Sends the InitializedEvent so that the debugger will continue
102102
// sending configuration requests
103103
_debugStateService.WaitingForAttach = false;
104-
_debugStateService.ServerStarted.SetResult(true);
104+
_debugStateService.ServerStarted.TrySetResult(true);
105105
}
106106
return;
107107

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public async Task<LaunchResponse> Handle(PsesLaunchRequestArguments request, Can
210210

211211
// Sends the InitializedEvent so that the debugger will continue
212212
// sending configuration requests
213-
_debugStateService.ServerStarted.SetResult(true);
213+
_debugStateService.ServerStarted.TrySetResult(true);
214214

215215
return new LaunchResponse();
216216
}
@@ -440,7 +440,7 @@ await _executionService.ExecutePSCommandAsync(
440440

441441
if (runspaceVersion.Version.Major >= 7)
442442
{
443-
_debugStateService.ServerStarted.SetResult(true);
443+
_debugStateService.ServerStarted.TrySetResult(true);
444444
}
445445
return new AttachResponse();
446446
}

test/PowerShellEditorServices.Test.E2E/DebugAdapterClientExtensions.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using System.Threading;
65
using System.Threading.Tasks;
76
using Microsoft.PowerShell.EditorServices.Handlers;
87
using OmniSharp.Extensions.DebugAdapter.Client;
@@ -29,10 +28,7 @@ public static async Task LaunchScript(this DebugAdapterClient debugAdapterClient
2928
}
3029

3130
// This will check to see if we received the Initialized event from the server.
32-
// NOTE: This needs to be spawned on a different thread, hence Task.Run().
33-
await Task.Run(
34-
async () => await started.Task.ConfigureAwait(true),
35-
CancellationToken.None).ConfigureAwait(true);
31+
await started.Task.ConfigureAwait(true);
3632
}
3733
}
3834
}

0 commit comments

Comments
 (0)