Codebase list golang-github-vbauerster-mpb / 38fe64f
refactoring: TestWithContext Vladimir Bauer 3 years ago
1 changed file(s) with 9 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
9292 func TestWithContext(t *testing.T) {
9393 shutdown := make(chan struct{})
9494 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
98101 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()
103105 }()
104
105 go p.Wait()
106106
107107 select {
108108 case <-shutdown: