Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset estimator of progress rate on backwards movement #483

Merged
merged 3 commits into from Sep 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/state.rs
Expand Up @@ -385,6 +385,11 @@ impl Estimator {
fn record(&mut self, new: u64, now: Instant) {
let delta = new.saturating_sub(self.prev.0);
if delta == 0 || now < self.prev.1 {
// Reset on backwards seek to prevent breakage from seeking to the end for length determination
// See https://github.com/console-rs/indicatif/issues/480
if new < self.prev.0 {
self.reset(now);
}
return;
}

Expand Down Expand Up @@ -617,8 +622,11 @@ mod tests {
let mut est = Estimator::new(now);
est.record(0, now);
est.record(1, now);
assert_eq!(est.len(), 1);
// Should not panic.
est.record(0, now);
// Assert that the state of the estimator reset on rewind
assert_eq!(est.len(), 0);

let pb = ProgressBar::hidden();
pb.set_length(10);
Expand Down