@@ -668,4 +668,52 @@ mod tests {
668668 }
669669 panic ! ( "Did not receive the event of {b_file2:?}" ) ;
670670 }
671+
672+ #[ test]
673+ fn update_paths_in_a_loop_with_errors ( ) -> StdResult < ( ) , Box < dyn std:: error:: Error > > {
674+ let dir = tempdir ( ) ?;
675+ let existing_dir_1 = dir. path ( ) . join ( "existing_dir_1" ) ;
676+ let not_existent_dir = dir. path ( ) . join ( "noт_existent_dir" ) ;
677+ let existing_dir_2 = dir. path ( ) . join ( "existing_dir_2" ) ;
678+
679+ fs:: create_dir ( & existing_dir_1) ?;
680+ fs:: create_dir ( & existing_dir_2) ?;
681+
682+ let mut paths_to_add = vec ! [
683+ PathOp :: watch_recursive( existing_dir_1. clone( ) ) ,
684+ PathOp :: watch_recursive( not_existent_dir. clone( ) ) ,
685+ PathOp :: watch_recursive( existing_dir_2. clone( ) ) ,
686+ ] ;
687+
688+ let ( tx, rx) = std:: sync:: mpsc:: channel ( ) ;
689+ let mut watcher = RecommendedWatcher :: new ( tx, Config :: default ( ) ) ?;
690+
691+ while !paths_to_add. is_empty ( ) {
692+ if let Err ( e) = watcher. update_paths ( std:: mem:: take ( & mut paths_to_add) ) {
693+ paths_to_add = e. remaining ;
694+ }
695+ }
696+
697+ fs:: create_dir ( existing_dir_1. join ( "1" ) ) ?;
698+ fs:: create_dir ( & not_existent_dir) ?;
699+ let waiting_path = existing_dir_2. join ( "1" ) ;
700+ fs:: create_dir ( & waiting_path) ?;
701+
702+ for event in iter_with_timeout ( & rx) {
703+ let path = event
704+ . paths
705+ . first ( )
706+ . unwrap_or_else ( || panic ! ( "event must have a path: {event:?}" ) ) ;
707+ assert ! (
708+ path != & not_existent_dir,
709+ "unexpeced {:?} event" ,
710+ not_existent_dir
711+ ) ;
712+ if path == & waiting_path {
713+ return Ok ( ( ) ) ;
714+ }
715+ }
716+
717+ panic ! ( "Did not receive the event of {waiting_path:?}" ) ;
718+ }
671719}
0 commit comments