@@ -22,11 +22,9 @@ namespace PowerShellEditorServices.Test.Session
2222 [ Trait ( "Category" , "PsesInternalHost" ) ]
2323 public class PsesInternalHostTests : IAsyncLifetime
2424 {
25- private readonly PsesInternalHost psesHost ;
25+ private PsesInternalHost psesHost ;
2626
27- public PsesInternalHostTests ( ) => psesHost = PsesHostFactory . Create ( NullLoggerFactory . Instance ) ;
28-
29- public Task InitializeAsync ( ) => Task . CompletedTask ;
27+ public async Task InitializeAsync ( ) => psesHost = await PsesHostFactory . Create ( NullLoggerFactory . Instance ) ;
3028
3129 public async Task DisposeAsync ( ) => await psesHost . StopAsync ( ) ;
3230
@@ -84,7 +82,7 @@ public async Task CanQueueParallelPSCommands()
8482 public async Task CanCancelExecutionWithToken ( )
8583 {
8684 using CancellationTokenSource cancellationSource = new ( millisecondsDelay : 1000 ) ;
87- _ = await Assert . ThrowsAsync < TaskCanceledException > ( ( ) =>
85+ await Assert . ThrowsAsync < TaskCanceledException > ( ( ) =>
8886 {
8987 return psesHost . ExecutePSCommandAsync (
9088 new PSCommand ( ) . AddScript ( "Start-Sleep 10" ) ,
@@ -100,9 +98,8 @@ public async Task CanCancelExecutionWithMethod()
10098 new PSCommand ( ) . AddScript ( "Start-Sleep 10" ) ,
10199 CancellationToken . None ) ;
102100
103- // Wait until our task has started.
104- Thread . Sleep ( 2000 ) ;
105- psesHost . CancelCurrentTask ( ) ;
101+ // Cancel the task after 1 second in another thread.
102+ Task . Run ( ( ) => { Thread . Sleep ( 1000 ) ; psesHost . CancelCurrentTask ( ) ; } ) ;
106103 await Assert . ThrowsAsync < TaskCanceledException > ( ( ) => executeTask ) ;
107104 Assert . True ( executeTask . IsCanceled ) ;
108105 }
@@ -236,11 +233,9 @@ public async Task CanHandleBadInitialWorkingDirectory(string path)
236233 [ Trait ( "Category" , "PsesInternalHost" ) ]
237234 public class PsesInternalHostWithProfileTests : IAsyncLifetime
238235 {
239- private readonly PsesInternalHost psesHost ;
240-
241- public PsesInternalHostWithProfileTests ( ) => psesHost = PsesHostFactory . Create ( NullLoggerFactory . Instance , loadProfiles : true ) ;
236+ private PsesInternalHost psesHost ;
242237
243- public Task InitializeAsync ( ) => Task . CompletedTask ;
238+ public async Task InitializeAsync ( ) => psesHost = await PsesHostFactory . Create ( NullLoggerFactory . Instance , loadProfiles : true ) ;
244239
245240 public async Task DisposeAsync ( ) => await psesHost . StopAsync ( ) ;
246241
0 commit comments