Skip to content

Commit 954e6e2

Browse files
committed
fixed progress reporting for distinct consecutive events
1 parent 78b02d9 commit 954e6e2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tmc-langs-util/src/progress_reporter.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ pub fn finish_stage<T: 'static + Send + Sync>(message: String, data: Option<T>)
154154
let _r = progress_reporter.progress_report.as_ref()(status_update);
155155
}
156156
}
157+
158+
// All of the stages have been finished, resetting progress for future events.
159+
if reporter.total_steps_left == 0 && (reporter.current_progress - 1.0_f64).abs() < 0.001 {
160+
reporter.current_progress = 0.0;
161+
}
157162
}
158163
}
159164

@@ -237,4 +242,35 @@ mod test {
237242
finish_stage::<usize>("msg".to_string(), None);
238243
assert!((su.lock().unwrap().as_ref().unwrap().percent_done - 1.0000).abs() < 0.01);
239244
}
245+
246+
#[test]
247+
fn consecutive_progress() {
248+
let _lock = init();
249+
250+
let su = Arc::new(Mutex::new(None));
251+
let suc = Arc::clone(&su);
252+
subscribe::<usize, _>(move |s| {
253+
log::debug!("got {:#?}", s);
254+
*suc.lock().unwrap() = Some(s);
255+
});
256+
257+
start_stage::<usize>(3, "starting".to_string(), None);
258+
progress_stage::<usize>("hello".to_string(), None);
259+
assert!(
260+
(su.lock().unwrap().as_ref().unwrap().percent_done - (1.0000 / 3.0000)).abs() < 0.01
261+
);
262+
progress_stage::<usize>("hello!".to_string(), Some(2));
263+
assert!(
264+
(su.lock().unwrap().as_ref().unwrap().percent_done - (2.0000 / 3.0000)).abs() < 0.01
265+
);
266+
finish_stage::<usize>("finished".to_string(), None);
267+
assert!((su.lock().unwrap().as_ref().unwrap().percent_done - 1.0000).abs() < 0.01);
268+
269+
start_stage::<usize>(2, "starting".to_string(), None);
270+
assert!((su.lock().unwrap().as_ref().unwrap().percent_done - 0.0000).abs() < 0.01);
271+
progress_stage::<usize>("hello".to_string(), None);
272+
assert!((su.lock().unwrap().as_ref().unwrap().percent_done - 0.5000).abs() < 0.01);
273+
progress_stage::<usize>("hello!".to_string(), Some(2));
274+
assert!((su.lock().unwrap().as_ref().unwrap().percent_done - 1.0000).abs() < 0.01);
275+
}
240276
}

0 commit comments

Comments
 (0)