refactoring: TestWithContext
Vladimir Bauer
3 years ago
| 92 | 92 | func TestWithContext(t *testing.T) { |
| 93 | 93 | shutdown := make(chan struct{}) |
| 94 | 94 | ctx, cancel := context.WithCancel(context.Background()) |
| 95 | p := mpb.NewWithContext(ctx, mpb.WithShutdownNotifier(shutdown), mpb.WithOutput(io.Discard)) | |
| 96 | ||
| 97 | bar := p.AddBar(0) // never complete bar | |
| 95 | p := mpb.NewWithContext(ctx, | |
| 96 | mpb.WithShutdownNotifier(shutdown), | |
| 97 | mpb.WithOutput(io.Discard), | |
| 98 | ) | |
| 99 | _ = p.AddBar(0) // never complete bar | |
| 100 | _ = p.AddBar(0) // never complete bar | |
| 98 | 101 | go func() { |
| 99 | for !bar.Aborted() { | |
| 100 | time.Sleep(randomDuration(100 * time.Millisecond)) | |
| 101 | cancel() | |
| 102 | } | |
| 102 | time.Sleep(randomDuration(100 * time.Millisecond)) | |
| 103 | cancel() | |
| 104 | p.Wait() | |
| 103 | 105 | }() |
| 104 | ||
| 105 | go p.Wait() | |
| 106 | 106 | |
| 107 | 107 | select { |
| 108 | 108 | case <-shutdown: |