Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 6ace68d

Browse files
committed
Add several additional Process wait tests
More complicated waiting scenarios.
1 parent 592d2c4 commit 6ace68d

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,71 @@ public void SingleProcess_CopiesShareExitInformation()
121121
}
122122
}
123123

124+
[Fact]
125+
public void WaitForPeerProcess()
126+
{
127+
Process child1 = CreateProcessInfinite();
128+
child1.Start();
129+
130+
Process child2 = CreateProcess(peerId =>
131+
{
132+
Process peer = Process.GetProcessById(int.Parse(peerId));
133+
Console.WriteLine("Signal");
134+
Assert.True(peer.WaitForExit(WaitInMS));
135+
return SuccessExitCode;
136+
}, child1.Id.ToString());
137+
child2.StartInfo.RedirectStandardOutput = true;
138+
child2.Start();
139+
Assert.Equal("Signal", child2.StandardOutput.ReadLine()); // wait for the signal before killing the peer
140+
141+
child1.Kill();
142+
Assert.True(child1.WaitForExit(WaitInMS));
143+
Assert.True(child2.WaitForExit(WaitInMS));
144+
145+
Assert.Equal(SuccessExitCode, child2.ExitCode);
146+
}
147+
148+
[Fact]
149+
public void WaitChain()
150+
{
151+
Process root = CreateProcess(() =>
152+
{
153+
Process child1 = CreateProcess(() =>
154+
{
155+
Process child2 = CreateProcess(() =>
156+
{
157+
Process child3 = CreateProcess(() => SuccessExitCode);
158+
child3.Start();
159+
Assert.True(child3.WaitForExit(WaitInMS));
160+
return child3.ExitCode;
161+
});
162+
child2.Start();
163+
Assert.True(child2.WaitForExit(WaitInMS));
164+
return child2.ExitCode;
165+
});
166+
child1.Start();
167+
Assert.True(child1.WaitForExit(WaitInMS));
168+
return child1.ExitCode;
169+
});
170+
root.Start();
171+
Assert.True(root.WaitForExit(WaitInMS));
172+
Assert.Equal(SuccessExitCode, root.ExitCode);
173+
}
174+
175+
[Fact]
176+
public void WaitForSelfTerminatingChild()
177+
{
178+
Process child = CreateProcess(() =>
179+
{
180+
Process.GetCurrentProcess().Kill();
181+
Assert.False(true, "Shouldn't get here");
182+
return SuccessExitCode;
183+
});
184+
child.Start();
185+
Assert.True(child.WaitForExit(WaitInMS));
186+
Assert.NotEqual(SuccessExitCode, child.ExitCode);
187+
}
188+
189+
124190
}
125191
}

0 commit comments

Comments
 (0)