@@ -20,12 +20,13 @@ public async Task WaitForExitAsync_DoesNotHangForOrphanedGrandChildren()
20
20
{
21
21
// This script creates a 'sleep' grandchild that outlives its parent.
22
22
File . WriteAllText ( filename ,
23
- $ """
24
- #!/bin/bash
23
+ $@ "#!/bin/bash
25
24
26
- sleep { GrandChildAgeSeconds } &
27
- """ ) ;
28
- File . SetUnixFileMode ( filename , UnixFileMode . UserRead | UnixFileMode . UserWrite | UnixFileMode . UserExecute ) ;
25
+ sleep { GrandChildAgeSeconds } &
26
+ " ) ;
27
+ Process chmodProcess = Process . Start ( "chmod" , $ "+x { filename } ") ;
28
+ chmodProcess . WaitForExit ( ) ;
29
+ Assert . Equal ( 0 , chmodProcess . ExitCode ) ;
29
30
30
31
var psi = new ProcessStartInfo ( )
31
32
{
@@ -36,14 +37,16 @@ public async Task WaitForExitAsync_DoesNotHangForOrphanedGrandChildren()
36
37
using Process process = Process . Start ( psi ) ;
37
38
38
39
// Use a shorter timeout for WaitForExitAsync than the grandchild lives.
39
- long startTime = Stopwatch . GetTimestamp ( ) ;
40
+ Stopwatch stopWatch = new Stopwatch ( ) ;
41
+ stopWatch . Start ( ) ;
40
42
using var cts = new CancellationTokenSource ( TimeSpan . FromSeconds ( WaitTimeoutSeconds ) ) ;
41
43
42
44
// The WaitForExit completes by cancellation.
43
45
await Assert . ThrowsAsync < TaskCanceledException > ( ( ) => process . WaitForExitAsync ( cts . Token , new StringWriter ( ) , new StringWriter ( ) ) ) ;
44
46
45
47
// The completion takes at least the WaitTime.
46
- TimeSpan elapsedTime = Stopwatch . GetElapsedTime ( startTime ) ;
48
+ stopWatch . Stop ( ) ;
49
+ TimeSpan elapsedTime = stopWatch . Elapsed ;
47
50
Assert . True ( elapsedTime >= TimeSpan . FromSeconds ( WaitTimeoutSeconds ) , "The grandchild is not keeping the script alive" ) ;
48
51
}
49
52
finally
0 commit comments