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

[Console][ProgressHelper] Fix ProgressHelper redraw when redrawFreq is greater than 1 #9420

Merged
merged 1 commit into from Nov 9, 2013

Conversation

giosh94mhz
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

When using a ProgressHelper object with redrawFreq > 1, there are situation where redraw may never occur.
E.g.

redrawFreq = 2
setContent = 1
advance(2) ... the redraw event is detected by 0 == current % redrawFreq.

I've tested the patch against phpunit and my local environment.

Maybe, a new test can be implemented to avoid the previous example, but I'm not familiar with mock object... :)

@giosh94mhz
Copy link
Contributor Author

I've amended few changes:

  • changed names (prevSlot/currSlot => prevPeriod/currPeriod)
  • added a unit test which show the wrong behaviour of the previous version
  • always redraw when completed

...and rebased to upstream/2.3.

if ($redraw || 0 === $this->current % $this->redrawFreq) {

$currPeriod = intval($this->current / $this->redrawFreq);
if ($redraw || $prevPeriod != $currPeriod || $this->max === $this->current) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a strict comparison

@giosh94mhz
Copy link
Contributor Author

@stof Thanks, I didn't noticed it.

@stof
Copy link
Member

stof commented Nov 5, 2013

@fabpot What about removing code duplication by rewriting advance() to reuse setCurrent ?

public function advance($step = 1, $redraw = false)
{
    $this->setCurrent($this->current + $step, $redraw);
}

the only change would be that advancing from a negative step would be forbidden. But I don't think it works properly currently anyway (IIRC, this is the reason why setCurrent has a check on the new value).
And it does not make sense to have the progress advance from a negative step anyway

fabpot added a commit that referenced this pull request Nov 9, 2013
…drawFreq is greater than 1 (giosh94mhz)

This PR was merged into the 2.3 branch.

Discussion
----------

[Console][ProgressHelper] Fix ProgressHelper redraw when redrawFreq is greater than 1

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

When using a ProgressHelper object with redrawFreq > 1, there are situation where redraw may never occur.
E.g.

    redrawFreq = 2
    setContent = 1
    advance(2) ... the redraw event is detected by 0 == current % redrawFreq.

I've tested the patch against phpunit and my local environment.

Maybe, a new test can be implemented to avoid the previous example, but I'm not familiar with mock object... :)

Commits
-------

5eca1fb Fix ProgressHelper redraw when redrawFreq is greater than 1
@fabpot fabpot merged commit 5eca1fb into symfony:2.3 Nov 9, 2013
fabpot added a commit that referenced this pull request Nov 9, 2013
@giosh94mhz giosh94mhz deleted the fix_ProgressHelper_freq_gt_1 branch July 23, 2014 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants