forked from grafana/tempo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexclusivequeues_test.go
More file actions
106 lines (85 loc) · 2.1 KB
/
exclusivequeues_test.go
File metadata and controls
106 lines (85 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package flushqueues
import (
"testing"
"github.com/google/uuid"
"github.com/grafana/tempo/pkg/util/test"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
)
type mockOp struct {
key string
}
func (m mockOp) Key() string {
return m.key
}
func (m mockOp) Priority() int64 {
return 0
}
func TestExclusiveQueues(t *testing.T) {
gauge := prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "test",
Name: "testersons",
})
q := New(1, gauge)
op := mockOp{
key: "not unique",
}
// enqueue twice
q.Enqueue(op)
length, err := test.GetGaugeValue(gauge)
assert.NoError(t, err)
assert.Equal(t, 1, int(length))
q.Enqueue(op)
length, err = test.GetGaugeValue(gauge)
assert.NoError(t, err)
assert.Equal(t, 1, int(length))
// dequeue -> requeue
_ = q.Dequeue(0)
length, err = test.GetGaugeValue(gauge)
assert.NoError(t, err)
assert.Equal(t, 0, int(length))
q.Requeue(op)
length, err = test.GetGaugeValue(gauge)
assert.NoError(t, err)
assert.Equal(t, 1, int(length))
// dequeue -> clearkey -> enqueue
_ = q.Dequeue(0)
length, err = test.GetGaugeValue(gauge)
assert.NoError(t, err)
assert.Equal(t, 0, int(length))
q.Clear(op)
length, err = test.GetGaugeValue(gauge)
assert.NoError(t, err)
assert.Equal(t, 0, int(length))
q.Enqueue(op)
length, err = test.GetGaugeValue(gauge)
assert.NoError(t, err)
assert.Equal(t, 1, int(length))
}
func TestMultipleQueues(t *testing.T) {
gauge := prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "test",
Name: "testersons",
})
totalQueues := 10
totalItems := 10
q := New(totalQueues, gauge)
// add stuff to the queue and confirm the length matches expected
for i := 0; i < totalItems; i++ {
op := mockOp{
key: uuid.New().String(),
}
q.Enqueue(op)
length, err := test.GetGaugeValue(gauge)
assert.NoError(t, err)
assert.Equal(t, i+1, int(length))
}
// each queue should have 1 thing
for i := 0; i < totalQueues; i++ {
op := q.Dequeue(i)
assert.NotNil(t, op)
length, err := test.GetGaugeValue(gauge)
assert.NoError(t, err)
assert.Equal(t, totalQueues-(i+1), int(length))
}
}