Skip to content

Commit

Permalink
Merge pull request #448 from cloudskiff/fix/progressBarResume
Browse files Browse the repository at this point in the history
Resume progress bar after timeout
  • Loading branch information
sundowndev authored Apr 26, 2021
2 parents 44d1a8e + 30bc979 commit 9d01944
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions pkg/output/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ func (p *progress) Stop() {
}

func (p *progress) Inc() {
if p.started.Load() {
p.count.Inc()
if lastVal := p.count.Load(); !p.started.Load() {
logrus.Debug("Progress received a tic after stopping. Restarting...")
p.Start()
p.count.Store(lastVal)
}
p.count.Inc()
}

func (p *progress) Val() uint64 {
Expand Down
14 changes: 9 additions & 5 deletions pkg/output/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import (
func TestProgressTimeoutDoesNotInc(t *testing.T) {
progress := NewProgress()
progress.Start()
progress.Inc()
progress.Stop() // should not hang
progress.Inc() // should not hang or inc
assert.Equal(t, uint64(0), progress.Val())
progress.Inc() // should restart progress and inc
assert.Equal(t, uint64(2), progress.Val())
assert.Equal(t, true, progress.started.Load())

progress.Stop()
assert.Equal(t, false, progress.started.Load())
}

func TestProgressTimeoutDoesNotHang(t *testing.T) {
Expand All @@ -21,10 +26,9 @@ func TestProgressTimeoutDoesNotHang(t *testing.T) {
time.Sleep(progressTimeout)
for progress.started.Load() == true {
}
progress.Inc() // should not hang or inc
progress.Inc() // should not hang but inc
progress.Stop() // should not hang
assert.Equal(t, uint64(0), progress.Val())

assert.Equal(t, uint64(1), progress.Val())
}

func TestProgress(t *testing.T) {
Expand Down

0 comments on commit 9d01944

Please sign in to comment.