simplify TestBarCount
Vladimir Bauer
4 years ago
| 22 | 22 | shutdown := make(chan struct{}) |
| 23 | 23 | p := mpb.New(mpb.WithShutdownNotifier(shutdown), mpb.WithOutput(ioutil.Discard)) |
| 24 | 24 | |
| 25 | check := make(chan struct{}) | |
| 26 | b := p.AddBar(100) | |
| 27 | go func() { | |
| 28 | for i := 0; i < 100; i++ { | |
| 29 | if i == 10 { | |
| 30 | close(check) | |
| 31 | } | |
| 32 | b.Increment() | |
| 33 | time.Sleep(randomDuration(100 * time.Millisecond)) | |
| 34 | } | |
| 35 | }() | |
| 25 | b := p.AddBar(0, mpb.BarRemoveOnComplete()) | |
| 36 | 26 | |
| 37 | <-check | |
| 38 | 27 | if count := p.BarCount(); count != 1 { |
| 39 | t.Errorf("BarCount want: %q, got: %q\n", 1, count) | |
| 28 | t.Errorf("BarCount want: %d, got: %d\n", 1, count) | |
| 40 | 29 | } |
| 41 | 30 | |
| 42 | b.Abort(false) | |
| 31 | b.SetTotal(100, true) | |
| 32 | ||
| 33 | if count := p.BarCount(); count != 0 { | |
| 34 | t.Errorf("BarCount want: %d, got: %d\n", 0, count) | |
| 35 | } | |
| 36 | ||
| 43 | 37 | go p.Wait() |
| 38 | ||
| 44 | 39 | select { |
| 45 | 40 | case <-shutdown: |
| 46 | 41 | case <-time.After(timeout): |