@@ -121,5 +121,71 @@ public void SingleProcess_CopiesShareExitInformation()
121
121
}
122
122
}
123
123
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
+
124
190
}
125
191
}
0 commit comments