@@ -272,11 +272,10 @@ public async Task WorkerProcess_WaitForExit_NotStarted_Throws()
272
272
public async Task WorkerProcess_WaitForExit_Success_TaskCompletes ( )
273
273
{
274
274
// 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 ) ;
280
279
using var rpcWorkerProcess = GetRpcWorkerConfigProcess (
281
280
TestHelpers . GetTestWorkerConfigsWithExecutableWorkingDirectory ( ) . ElementAt ( 0 ) ) ;
282
281
@@ -291,11 +290,10 @@ public async Task WorkerProcess_WaitForExit_Success_TaskCompletes()
291
290
public async Task WorkerProcess_WaitForExit_Error_Rethrows ( )
292
291
{
293
292
// 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 ) ;
299
297
using var rpcWorkerProcess = GetRpcWorkerConfigProcess (
300
298
TestHelpers . GetTestWorkerConfigsWithExecutableWorkingDirectory ( ) . ElementAt ( 0 ) ) ;
301
299
@@ -312,33 +310,13 @@ private static Process GetProcess(int exitCode)
312
310
{
313
311
StartInfo = new ( )
314
312
{
313
+ WindowStyle = ProcessWindowStyle . Hidden ,
315
314
FileName = OperatingSystem . IsWindows ( ) ? "cmd" : "bash" ,
316
315
Arguments = OperatingSystem . IsWindows ( ) ? $ "/C exit { exitCode } " : $ "-c \" exit { exitCode } \" ",
317
316
RedirectStandardError = true ,
318
317
RedirectStandardOutput = true ,
319
- CreateNoWindow = true ,
320
- ErrorDialog = false ,
321
- UseShellExecute = false
322
318
}
323
319
} ;
324
320
}
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
- }
343
321
}
344
322
}
0 commit comments