Skip to content

Commit e6482f4

Browse files
authored
Give the nested process chain in ProcessWaitingTests depth-proportional wait budgets (#135608)
Fixes #118977 ## Problem `ProcessWaitingTests.WaitChain` and `WaitAsyncChain` start a four-deep chain of `RemoteExecutor` processes, and every level waits with the same `WaitInMS`. The root's wait has to cover the start-up, work and exit of all four processes while the leaf's covers one, so the root has the leaf's budget while covering four lifetimes. ## Change Give each waiter `WaitInMS` per process beneath it: leaf 1×, then 2×, 3× and 4× at the root. > [!NOTE] > This PR was prepared with AI assistance (Anthropic Claude, checked by OpenAI Codex) at my request. I reviewed the change and the measurements before opening it.
1 parent 0d73c1f commit e6482f4

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎src/libraries/System.Diagnostics.Process/tests/ProcessWaitingTests.cs‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,10 @@ public async Task WaitForExitAsync_AfterProcessExit_ShouldConsumeOutputDataRecei
542542
Assert.Equal(1, linesReceived);
543543
}
544544

545+
// A waiter in a nested process chain covers the start-up, work and exit of every process beneath it, so its
546+
// budget grows with the number of processes below.
547+
private static int ChainWaitInMS(int processesBelow) => WaitInMS * processesBelow;
548+
545549
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
546550
public void WaitChain()
547551
{
@@ -553,19 +557,19 @@ public void WaitChain()
553557
{
554558
Process child3 = CreateProcess(() => RemoteExecutor.SuccessExitCode);
555559
child3.Start();
556-
Assert.True(child3.WaitForExit(WaitInMS));
560+
Assert.True(child3.WaitForExit(ChainWaitInMS(1)));
557561
return child3.ExitCode;
558562
});
559563
child2.Start();
560-
Assert.True(child2.WaitForExit(WaitInMS));
564+
Assert.True(child2.WaitForExit(ChainWaitInMS(2)));
561565
return child2.ExitCode;
562566
});
563567
child1.Start();
564-
Assert.True(child1.WaitForExit(WaitInMS));
568+
Assert.True(child1.WaitForExit(ChainWaitInMS(3)));
565569
return child1.ExitCode;
566570
});
567571
root.Start();
568-
Assert.True(root.WaitForExit(WaitInMS));
572+
Assert.True(root.WaitForExit(ChainWaitInMS(4)));
569573
Assert.Equal(RemoteExecutor.SuccessExitCode, root.ExitCode);
570574
}
571575

@@ -580,7 +584,7 @@ public async Task WaitAsyncChain()
580584
{
581585
Process child3 = CreateProcess(() => RemoteExecutor.SuccessExitCode);
582586
child3.Start();
583-
using (var cts = new CancellationTokenSource(WaitInMS))
587+
using (var cts = new CancellationTokenSource(ChainWaitInMS(1)))
584588
{
585589
await child3.WaitForExitAsync(cts.Token);
586590
Assert.True(child3.HasExited);
@@ -589,7 +593,7 @@ public async Task WaitAsyncChain()
589593
return child3.ExitCode;
590594
});
591595
child2.Start();
592-
using (var cts = new CancellationTokenSource(WaitInMS))
596+
using (var cts = new CancellationTokenSource(ChainWaitInMS(2)))
593597
{
594598
await child2.WaitForExitAsync(cts.Token);
595599
Assert.True(child2.HasExited);
@@ -598,7 +602,7 @@ public async Task WaitAsyncChain()
598602
return child2.ExitCode;
599603
});
600604
child1.Start();
601-
using (var cts = new CancellationTokenSource(WaitInMS))
605+
using (var cts = new CancellationTokenSource(ChainWaitInMS(3)))
602606
{
603607
await child1.WaitForExitAsync(cts.Token);
604608
Assert.True(child1.HasExited);
@@ -607,7 +611,7 @@ public async Task WaitAsyncChain()
607611
return child1.ExitCode;
608612
});
609613
root.Start();
610-
using (var cts = new CancellationTokenSource(WaitInMS))
614+
using (var cts = new CancellationTokenSource(ChainWaitInMS(4)))
611615
{
612616
await root.WaitForExitAsync(cts.Token);
613617
Assert.True(root.HasExited);

0 commit comments

Comments
 (0)