@@ -123,3 +123,62 @@ pub async fn kill_tree_with_config(process_id: ProcessId, config: &Config) -> Re
123123 let process_infos = process_infos_provider. get_process_infos ( ) . await ?;
124124 crate :: common:: kill_tree_internal ( process_id, config, process_infos)
125125}
126+
127+ #[ cfg( test) ]
128+ mod tests {
129+ use super :: * ;
130+ use crate :: get_available_max_process_id;
131+
132+ #[ :: tokio:: test]
133+ async fn kill_tree_available_max_process_id ( ) {
134+ let target_process_id = get_available_max_process_id ( ) ;
135+ let outputs = kill_tree ( target_process_id) . await . expect ( "Failed to kill" ) ;
136+ assert ! ( outputs. len( ) > 0 ) ;
137+ let output = & outputs[ 0 ] ;
138+ match output {
139+ crate :: Output :: Killed { .. } => {
140+ panic ! ( "This should not happen" ) ;
141+ }
142+ crate :: Output :: MaybeAlreadyTerminated { process_id, source } => {
143+ assert_eq ! ( * process_id, target_process_id) ;
144+ assert_eq ! ( source. to_string( ) , "Unix error: ESRCH: No such process" ) ;
145+ }
146+ }
147+ }
148+
149+ #[ :: tokio:: test]
150+ async fn kill_tree_with_config_sigkill_available_max_process_id ( ) {
151+ let target_process_id = get_available_max_process_id ( ) ;
152+ let config = Config {
153+ signal : String :: from ( "SIGKILL" ) ,
154+ ..Default :: default ( )
155+ } ;
156+ let outputs = kill_tree_with_config ( target_process_id, & config)
157+ . await
158+ . expect ( "Failed to kill" ) ;
159+ assert ! ( outputs. len( ) > 0 ) ;
160+ let output = & outputs[ 0 ] ;
161+ match output {
162+ crate :: Output :: Killed { .. } => {
163+ panic ! ( "This should not happen" ) ;
164+ }
165+ crate :: Output :: MaybeAlreadyTerminated { process_id, source } => {
166+ assert_eq ! ( * process_id, target_process_id) ;
167+ assert_eq ! ( source. to_string( ) , "Unix error: ESRCH: No such process" ) ;
168+ }
169+ }
170+ }
171+
172+ #[ :: tokio:: test]
173+ async fn kill_tree_with_config_include_target_false_available_max_process_id ( ) {
174+ let target_process_id = get_available_max_process_id ( ) ;
175+ let config = Config {
176+ include_target : false ,
177+ ..Default :: default ( )
178+ } ;
179+ let outputs = kill_tree_with_config ( target_process_id, & config)
180+ . await
181+ . expect ( "Failed to kill" ) ;
182+ assert ! ( outputs. len( ) == 0 ) ;
183+ }
184+ }
0 commit comments