MCPcopy
hub / github.com/prometheus/prometheus / TestSampleRing

Function TestSampleRing

storage/buffer_test.go:27–90  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestSampleRing(t *testing.T) {
28 cases := []struct {
29 input []int64
30 delta int64
31 size int
32 }{
33 {
34 input: []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
35 delta: 2,
36 size: 1,
37 },
38 {
39 input: []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
40 delta: 2,
41 size: 2,
42 },
43 {
44 input: []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
45 delta: 7,
46 size: 3,
47 },
48 {
49 input: []int64{1, 2, 3, 4, 5, 16, 17, 18, 19, 20},
50 delta: 7,
51 size: 1,
52 },
53 {
54 input: []int64{1, 2, 3, 4, 6},
55 delta: 4,
56 size: 4,
57 },
58 }
59 for _, c := range cases {
60 r := newSampleRing(c.delta, c.size, chunkenc.ValFloat)
61
62 input := []fSample{}
63 for _, t := range c.input {
64 // Randomize start timestamp to make sure it does not affect the
65 // outcome.
66 input = append(input, fSample{st: rand.Int63(), t: t, f: float64(rand.Intn(100))})
67 }
68
69 for i, s := range input {
70 r.add(s)
71 buffered := r.samples()
72
73 for _, sold := range input[:i] {
74 found := false
75 for _, bs := range buffered {
76 if bs.T() == sold.t && bs.F() == sold.f {
77 found = true
78 break
79 }
80 }
81
82 if found {
83 require.GreaterOrEqual(t, sold.t, s.t-c.delta, "%d: unexpected sample %d in buffer; buffer %v", i, sold.t, buffered)
84 } else {

Callers

nothing calls this directly

Calls 6

newSampleRingFunction · 0.85
samplesMethod · 0.80
addMethod · 0.65
TMethod · 0.65
FMethod · 0.65
LessMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…