Codebase list golang-github-vbauerster-mpb / b865347
TestDecorStatisticsAvailableWidth refactoring Vladimir Bauer 5 years ago
1 changed file(s) with 25 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
258258 if s.AvailableWidth != 80 {
259259 t.Errorf("expected AvailableWidth %d got %d\n", 80, s.AvailableWidth)
260260 }
261 return fmt.Sprintf("\x1b[31;1;4m%s\x1b[0m", strings.Repeat("1", 20))
262 }
261 return fmt.Sprintf("\x1b[31;1;4m%s\x1b[0m", strings.Repeat("0", 20))
262 }
263 checkDone := make(chan struct{})
263264 td2 := func(s decor.Statistics) string {
264 if s.AvailableWidth != 60 {
265 t.Errorf("expected AvailableWidth %d got %d\n", 60, s.AvailableWidth)
265 defer func() {
266 checkDone <- struct{}{}
267 }()
268 if s.AvailableWidth != 40 {
269 t.Errorf("expected AvailableWidth %d got %d\n", 40, s.AvailableWidth)
266270 }
267271 return ""
268272 }
269273 total := 100
274 down := make(chan struct{})
270275 p := mpb.New(
271276 mpb.WithWidth(100),
277 mpb.WithShutdownNotifier(down),
272278 mpb.WithOutput(ioutil.Discard),
273279 )
274280 bar := p.AddBar(int64(total),
278284 decor.Any(td1),
279285 ),
280286 mpb.AppendDecorators(
287 decor.Name(strings.Repeat("0", 20)),
281288 decor.Any(td2),
282289 ),
283290 )
284 for i := 0; i < total; i++ {
285 time.Sleep(10 * time.Millisecond)
286 bar.Increment()
287 }
291 go func() {
292 for {
293 select {
294 case <-checkDone:
295 bar.Abort(false)
296 case <-down:
297 return
298 }
299 }
300 }()
301 for !bar.Completed() {
302 bar.Increment()
303 }
304 p.Wait()
288305 }
289306
290307 func panicDecorator(panicMsg string, cond func(decor.Statistics) bool) decor.Decorator {