process: Don't kill child on drop if already successfully killed
@@ -398,7 +398,13 @@ impl<T: Kill> ChildDropGuard<T> {
impl<T: Kill> Kill for ChildDropGuard<T> {
fn kill(&mut self) -> io::Result<()> {
- self.inner.kill()
+ let ret = self.inner.kill();
+
+ if ret.is_ok() {
+ self.kill_on_drop = false;
+ }
+
+ ret
}
}
@@ -811,6 +817,20 @@ mod test {
assert_eq!(0, mock.num_polls);
}
+ #[test]
+ fn no_kill_if_already_killed() {
+ let mut mock = Mock::new();
+
+ {
+ let mut guard = ChildDropGuard::new(&mut mock);
+ let _ = guard.kill();
+ drop(guard);
+ }
+
+ assert_eq!(1, mock.num_kills);
+ assert_eq!(0, mock.num_polls);
+ }
+
#[test]
fn no_kill_if_reaped() {
let mut mock_pending = Mock::with_result(Ok(Async::NotReady));
