MCPcopy
hub / github.com/garethgeorge/backrest / TestTPQPriority

Function TestTPQPriority

internal/queue/timepriorityqueue_test.go:12–31  ·  view source on GitHub ↗

TestTPQEnqueue tests that enqueued elements are retruned highest priority first.

(t *testing.T)

Source from the content-addressed store, hash-verified

10
11// TestTPQEnqueue tests that enqueued elements are retruned highest priority first.
12func 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
33func TestTPQMixedReadinessStates(t *testing.T) {
34 t.Parallel()

Callers

nothing calls this directly

Calls 4

AddMethod · 0.65
EnqueueMethod · 0.45
LenMethod · 0.45
DequeueMethod · 0.45

Tested by

no test coverage detected