diff --git a/plugins/callback/dashboard.py b/plugins/callback/dashboard.py index 2dbf8a621..66836dcc5 100644 --- a/plugins/callback/dashboard.py +++ b/plugins/callback/dashboard.py @@ -195,14 +195,17 @@ def hms(seconds): def eta(step, total, play_start, step_start, now): """The remaining time of a play, or None before the first step is done. The - time the finished steps took per step, times the steps left, less the time the - running step already took. It gets more accurate towards the end of the play. + time the finished steps took per step, times the steps after the running one, + plus what is left of that step's share. A step that runs longer than the + average, like an include_tasks with dozens of tasks, does not eat into the + estimate for the steps after it. It gets more accurate towards the end of the + play. """ done = step - 1 if done < 1: return None per_step = (step_start - play_start) / done - return max(per_step * (total - done) - (now - step_start), 0) + return per_step * (total - step) + max(per_step - (now - step_start), 0) def progress_bar(step, total, width, color=True, remaining=None): diff --git a/tests/unit/plugins/callback/test_dashboard.py b/tests/unit/plugins/callback/test_dashboard.py index ff228060c..ce864fd71 100644 --- a/tests/unit/plugins/callback/test_dashboard.py +++ b/tests/unit/plugins/callback/test_dashboard.py @@ -261,7 +261,10 @@ def test_eta_from_the_finished_steps(self): self.assertEqual(_module.eta(7, 21, 100, 160, 164), 146) # no step done yet self.assertIsNone(_module.eta(1, 21, 100, 100, 130)) - # a step that takes longer than estimated does not go below zero + # a step that takes longer than the average, like a large include, keeps + # the estimate for the 14 steps after it + self.assertEqual(_module.eta(7, 21, 100, 160, 460), 140) + # and the last step does not go below zero self.assertEqual(_module.eta(21, 21, 0, 200, 900), 0)