MCPcopy
hub / github.com/prometheus/prometheus / assertInvariants

Method assertInvariants

tsdb/chunks/queue_test.go:26–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func (q *writeJobQueue) assertInvariants(t *testing.T) {
27 q.mtx.Lock()
28 defer q.mtx.Unlock()
29
30 totalSize := 0
31 for s := q.first; s != nil; s = s.nextSegment {
32 require.NotNil(t, s.segment)
33
34 // Next read index is lower or equal than next write index (we cannot past written jobs)
35 require.LessOrEqual(t, s.nextRead, s.nextWrite)
36
37 // Number of unread elements in this segment.
38 totalSize += s.nextWrite - s.nextRead
39
40 // First segment can be partially read, other segments were not read yet.
41 if s == q.first {
42 require.GreaterOrEqual(t, s.nextRead, 0)
43 } else {
44 require.Equal(t, 0, s.nextRead)
45 }
46
47 // If first shard is empty (everything was read from it already), it must have extra capacity for
48 // additional elements, otherwise it would have been removed.
49 if s == q.first && s.nextRead == s.nextWrite {
50 require.Less(t, s.nextWrite, len(s.segment))
51 }
52
53 // Segments in the middle are full.
54 if s != q.first && s != q.last {
55 require.Len(t, s.segment, s.nextWrite)
56 }
57 // Last segment must have at least one element, or we wouldn't have created it.
58 require.Positive(t, s.nextWrite)
59 }
60
61 require.Equal(t, q.size, totalSize)
62}
63
64func TestQueuePushPopSingleGoroutine(t *testing.T) {
65 t.Parallel()

Callers 1

Calls 3

LockMethod · 0.80
LenMethod · 0.65
LessMethod · 0.45

Tested by

no test coverage detected