TestBarInProgress
Vladimir Bauer
9 years ago
| 78 | 78 |
}
|
| 79 | 79 |
}
|
| 80 | 80 |
}
|
|
81 |
|
|
82 |
func TestBarInProgress(t *testing.T) {
|
|
83 |
var buf bytes.Buffer
|
|
84 |
cancel := make(chan struct{})
|
|
85 |
p := mpb.New().WithCancel(cancel).SetOut(&buf)
|
|
86 |
bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace()
|
|
87 |
|
|
88 |
stopped := make(chan struct{})
|
|
89 |
|
|
90 |
go func() {
|
|
91 |
defer close(stopped)
|
|
92 |
for bar.InProgress() {
|
|
93 |
time.Sleep(10 * time.Millisecond)
|
|
94 |
bar.Incr(1)
|
|
95 |
}
|
|
96 |
}()
|
|
97 |
|
|
98 |
time.Sleep(250 * time.Millisecond)
|
|
99 |
close(cancel)
|
|
100 |
p.Stop()
|
|
101 |
|
|
102 |
select {
|
|
103 |
case <-stopped:
|
|
104 |
case <-time.After(300 * time.Millisecond):
|
|
105 |
t.Error("bar.InProgress returns true after cancel")
|
|
106 |
}
|
|
107 |
}
|