Codebase list golang-github-vbauerster-mpb / 08ad434
TestUpdateBarPriority Vladimir Bauer 3 years ago
2 changed file(s) with 44 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
11
22 // make syncWidth func public in test
33 var SyncWidth = syncWidth
4
5 type PriorityQueue = priorityQueue
11
22 import (
33 "bytes"
4 "container/heap"
45 "context"
56 "errors"
67 "io"
163164 t.Errorf("Progress didn't shutdown after %v", timeout)
164165 }
165166 }
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 }