fix test timed out
Vladimir Bauer
4 years ago
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | func TestDecorStatisticsAvailableWidth(t *testing.T) { |
| 257 | total := 100 | |
| 258 | down := make(chan struct{}) | |
| 259 | checkDone := make(chan struct{}) | |
| 257 | 260 | td1 := func(s decor.Statistics) string { |
| 258 | 261 | if s.AvailableWidth != 80 { |
| 259 | 262 | t.Errorf("expected AvailableWidth %d got %d\n", 80, s.AvailableWidth) |
| 260 | 263 | } |
| 261 | 264 | return fmt.Sprintf("\x1b[31;1;4m%s\x1b[0m", strings.Repeat("0", 20)) |
| 262 | 265 | } |
| 263 | checkDone := make(chan struct{}) | |
| 264 | 266 | td2 := func(s decor.Statistics) string { |
| 265 | 267 | defer func() { |
| 266 | checkDone <- struct{}{} | |
| 268 | select { | |
| 269 | case checkDone <- struct{}{}: | |
| 270 | default: | |
| 271 | } | |
| 267 | 272 | }() |
| 268 | 273 | if s.AvailableWidth != 40 { |
| 269 | 274 | t.Errorf("expected AvailableWidth %d got %d\n", 40, s.AvailableWidth) |
| 270 | 275 | } |
| 271 | 276 | return "" |
| 272 | 277 | } |
| 273 | total := 100 | |
| 274 | down := make(chan struct{}) | |
| 275 | 278 | p := mpb.New( |
| 276 | 279 | mpb.WithWidth(100), |
| 277 | 280 | mpb.WithShutdownNotifier(down), |
| 292 | 295 | for { |
| 293 | 296 | select { |
| 294 | 297 | case <-checkDone: |
| 295 | bar.Abort(false) | |
| 298 | bar.Abort(true) | |
| 296 | 299 | case <-down: |
| 297 | 300 | return |
| 298 | 301 | } |