Codebase list golang-github-vbauerster-mpb / 5690ec4
TestBarInProgress Vladimir Bauer 9 years ago
2 changed file(s) with 28 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
347347 case <-b.removeReqCh:
348348 return
349349 case <-b.cancel:
350 close(b.completed)
350351 return
351352 }
352353 }
7878 }
7979 }
8080 }
81
82 func TestBarInProgress(t *testing.T) {
83 var buf bytes.Buffer
84 cancel := make(chan struct{})
85 p := mpb.New().WithCancel(cancel).SetOut(&buf)
86 bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace()
87
88 stopped := make(chan struct{})
89
90 go func() {
91 defer close(stopped)
92 for bar.InProgress() {
93 time.Sleep(10 * time.Millisecond)
94 bar.Incr(1)
95 }
96 }()
97
98 time.Sleep(250 * time.Millisecond)
99 close(cancel)
100 p.Stop()
101
102 select {
103 case <-stopped:
104 case <-time.After(300 * time.Millisecond):
105 t.Error("bar.InProgress returns true after cancel")
106 }
107 }