diff --git a/bar.go b/bar.go index d0de65d..0d7b58e 100644 --- a/bar.go +++ b/bar.go @@ -348,6 +348,7 @@ case <-b.removeReqCh: return case <-b.cancel: + close(b.completed) return } } diff --git a/bar_test.go b/bar_test.go index 38b42c8..de4171c 100644 --- a/bar_test.go +++ b/bar_test.go @@ -79,3 +79,30 @@ } } } + +func TestBarInProgress(t *testing.T) { + var buf bytes.Buffer + cancel := make(chan struct{}) + p := mpb.New().WithCancel(cancel).SetOut(&buf) + bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace() + + stopped := make(chan struct{}) + + go func() { + defer close(stopped) + for bar.InProgress() { + time.Sleep(10 * time.Millisecond) + bar.Incr(1) + } + }() + + time.Sleep(250 * time.Millisecond) + close(cancel) + p.Stop() + + select { + case <-stopped: + case <-time.After(300 * time.Millisecond): + t.Error("bar.InProgress returns true after cancel") + } +}