simplify TestWithContext
Vladimir Bauer
4 years ago
| 94 | 94 | p := mpb.NewWithContext(ctx, mpb.WithShutdownNotifier(shutdown), mpb.WithOutput(ioutil.Discard)) |
| 95 | 95 | |
| 96 | 96 | done := make(chan struct{}) |
| 97 | fail := make(chan struct{}) | |
| 98 | 97 | bar := p.AddBar(0) // never complete bar |
| 99 | 98 | go func() { |
| 100 | 99 | for !bar.Aborted() { |
| 105 | 104 | }() |
| 106 | 105 | |
| 107 | 106 | go func() { |
| 108 | select { | |
| 109 | case <-done: | |
| 110 | p.Wait() | |
| 111 | case <-time.After(timeout): | |
| 112 | close(fail) | |
| 113 | } | |
| 107 | <-done | |
| 108 | p.Wait() | |
| 114 | 109 | }() |
| 115 | 110 | |
| 116 | 111 | select { |
| 117 | 112 | case <-shutdown: |
| 118 | case <-fail: | |
| 113 | case <-time.After(timeout): | |
| 119 | 114 | t.Errorf("Progress didn't shutdown after %v", timeout) |
| 120 | 115 | } |
| 121 | 116 | } |