TestTPQEnqueue tests that enqueued elements are retruned highest priority first.
(t *testing.T)
| 10 | |
| 11 | // TestTPQEnqueue tests that enqueued elements are retruned highest priority first. |
| 12 | func TestTPQPriority(t *testing.T) { |
| 13 | t.Parallel() |
| 14 | tpq := NewTimePriorityQueue[val]() |
| 15 | |
| 16 | now := time.Now().Add(-time.Second) |
| 17 | for i := 0; i < 100; i++ { |
| 18 | tpq.Enqueue(now, i, val{i}) |
| 19 | } |
| 20 | |
| 21 | if tpq.Len() != 100 { |
| 22 | t.Errorf("expected length to be 100, got %d", tpq.Len()) |
| 23 | } |
| 24 | |
| 25 | for i := 99; i >= 0; i-- { |
| 26 | v := tpq.Dequeue(context.Background()) |
| 27 | if v.v != i { |
| 28 | t.Errorf("expected %d, got %d", i, v) |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | func TestTPQMixedReadinessStates(t *testing.T) { |
| 34 | t.Parallel() |