| 1 | 1 |
|
| 2 | 2 |
import (
|
| 3 | 3 |
"bytes"
|
|
4 |
"container/heap"
|
| 4 | 5 |
"context"
|
| 5 | 6 |
"errors"
|
| 6 | 7 |
"io"
|
|
| 163 | 164 |
t.Errorf("Progress didn't shutdown after %v", timeout)
|
| 164 | 165 |
}
|
| 165 | 166 |
}
|
|
167 |
|
|
168 |
func TestUpdateBarPriority(t *testing.T) {
|
|
169 |
shutdown := make(chan interface{})
|
|
170 |
ctx, cancel := context.WithCancel(context.Background())
|
|
171 |
p := mpb.NewWithContext(ctx,
|
|
172 |
mpb.WithOutput(io.Discard),
|
|
173 |
mpb.WithShutdownNotifier(shutdown),
|
|
174 |
)
|
|
175 |
a := p.AddBar(100, mpb.BarPriority(1))
|
|
176 |
b := p.AddBar(100, mpb.BarPriority(2))
|
|
177 |
c := p.AddBar(100, mpb.BarPriority(3))
|
|
178 |
|
|
179 |
identity := map[*mpb.Bar]string{
|
|
180 |
a: "a",
|
|
181 |
b: "b",
|
|
182 |
c: "c",
|
|
183 |
}
|
|
184 |
|
|
185 |
p.UpdateBarPriority(c, 2)
|
|
186 |
p.UpdateBarPriority(b, 3)
|
|
187 |
|
|
188 |
cancel()
|
|
189 |
|
|
190 |
bars := (<-shutdown).([]*mpb.Bar)
|
|
191 |
if l := len(bars); l != 3 {
|
|
192 |
t.Errorf("Expected len of bars: %d, got: %d", 3, l)
|
|
193 |
}
|
|
194 |
|
|
195 |
p.Wait()
|
|
196 |
pq := mpb.PriorityQueue(bars)
|
|
197 |
|
|
198 |
if bar := heap.Pop(&pq).(*mpb.Bar); bar != b {
|
|
199 |
t.Errorf("Expected bar b, got: %s", identity[bar])
|
|
200 |
}
|
|
201 |
if bar := heap.Pop(&pq).(*mpb.Bar); bar != c {
|
|
202 |
t.Errorf("Expected bar c, got: %s", identity[bar])
|
|
203 |
}
|
|
204 |
if bar := heap.Pop(&pq).(*mpb.Bar); bar != a {
|
|
205 |
t.Errorf("Expected bar a, got: %s", identity[bar])
|
|
206 |
}
|
|
207 |
}
|