Codebase list golang-github-vbauerster-mpb / e530451
simplify TestBarCount Vladimir Bauer 4 years ago
1 changed file(s) with 9 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
2222 shutdown := make(chan struct{})
2323 p := mpb.New(mpb.WithShutdownNotifier(shutdown), mpb.WithOutput(ioutil.Discard))
2424
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())
3626
37 <-check
3827 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)
4029 }
4130
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
4337 go p.Wait()
38
4439 select {
4540 case <-shutdown:
4641 case <-time.After(timeout):