@@ -272,11 +272,10 @@ public async Task WorkerProcess_WaitForExit_NotStarted_Throws()
272272 public async Task WorkerProcess_WaitForExit_Success_TaskCompletes ( )
273273 {
274274 // arrange
275- await using ProcessWrapper wrapper = new ( exitCode : 0 ) ;
276- _hostProcessMonitorMock . Setup ( m => m . RegisterChildProcess ( wrapper . Process ) ) ;
277- _hostProcessMonitorMock . Setup ( m => m . UnregisterChildProcess ( wrapper . Process ) ) ;
278- _workerProcessFactory . Setup ( m => m . CreateWorkerProcess ( It . IsNotNull < WorkerContext > ( ) ) )
279- . Returns ( wrapper . Process ) ;
275+ using Process process = GetProcess ( exitCode : 0 ) ;
276+ _hostProcessMonitorMock . Setup ( m => m . RegisterChildProcess ( process ) ) ;
277+ _hostProcessMonitorMock . Setup ( m => m . UnregisterChildProcess ( process ) ) ;
278+ _workerProcessFactory . Setup ( m => m . CreateWorkerProcess ( It . IsNotNull < WorkerContext > ( ) ) ) . Returns ( process ) ;
280279 using var rpcWorkerProcess = GetRpcWorkerConfigProcess (
281280 TestHelpers . GetTestWorkerConfigsWithExecutableWorkingDirectory ( ) . ElementAt ( 0 ) ) ;
282281
@@ -291,11 +290,10 @@ public async Task WorkerProcess_WaitForExit_Success_TaskCompletes()
291290 public async Task WorkerProcess_WaitForExit_Error_Rethrows ( )
292291 {
293292 // arrange
294- await using ProcessWrapper wrapper = new ( exitCode : - 1 ) ;
295- _hostProcessMonitorMock . Setup ( m => m . RegisterChildProcess ( wrapper . Process ) ) ;
296- _hostProcessMonitorMock . Setup ( m => m . UnregisterChildProcess ( wrapper . Process ) ) ;
297- _workerProcessFactory . Setup ( m => m . CreateWorkerProcess ( It . IsNotNull < WorkerContext > ( ) ) )
298- . Returns ( wrapper . Process ) ;
293+ using Process process = GetProcess ( exitCode : - 1 ) ;
294+ _hostProcessMonitorMock . Setup ( m => m . RegisterChildProcess ( process ) ) ;
295+ _hostProcessMonitorMock . Setup ( m => m . UnregisterChildProcess ( process ) ) ;
296+ _workerProcessFactory . Setup ( m => m . CreateWorkerProcess ( It . IsNotNull < WorkerContext > ( ) ) ) . Returns ( process ) ;
299297 using var rpcWorkerProcess = GetRpcWorkerConfigProcess (
300298 TestHelpers . GetTestWorkerConfigsWithExecutableWorkingDirectory ( ) . ElementAt ( 0 ) ) ;
301299
@@ -312,33 +310,13 @@ private static Process GetProcess(int exitCode)
312310 {
313311 StartInfo = new ( )
314312 {
313+ WindowStyle = ProcessWindowStyle . Hidden ,
315314 FileName = OperatingSystem . IsWindows ( ) ? "cmd" : "bash" ,
316315 Arguments = OperatingSystem . IsWindows ( ) ? $ "/C exit { exitCode } " : $ "-c \" exit { exitCode } \" ",
317316 RedirectStandardError = true ,
318317 RedirectStandardOutput = true ,
319- CreateNoWindow = true ,
320- ErrorDialog = false ,
321- UseShellExecute = false
322318 }
323319 } ;
324320 }
325-
326- private class ProcessWrapper ( int exitCode ) : IAsyncDisposable
327- {
328- public Process Process { get ; } = GetProcess ( exitCode ) ;
329-
330- public async ValueTask DisposeAsync ( )
331- {
332- if ( ! Process . HasExited )
333- {
334- // We need to kill the entire process tree to ensure
335- // CI tests don't hang due to child processes lingering around.
336- Process . Kill ( entireProcessTree : true ) ;
337- await Process . WaitForExitAsync ( ) ;
338- }
339-
340- Process . Dispose ( ) ;
341- }
342- }
343321 }
344322}
0 commit comments