MCPcopy Index your code
hub / github.com/prometheus/prometheus / TestQueuePopBlocksOnEmptyQueue

Function TestQueuePopBlocksOnEmptyQueue

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

Source from the content-addressed store, hash-verified

154}
155
156func TestQueuePopBlocksOnEmptyQueue(t *testing.T) {
157 t.Parallel()
158 queue := newWriteJobQueue(5, 5)
159
160 popTime := make(chan time.Time)
161 go func() {
162 j, b := queue.pop()
163 require.True(t, b)
164 require.Equal(t, HeadSeriesRef(1), j.seriesRef)
165
166 popTime <- time.Now()
167
168 // This will block
169 j, b = queue.pop()
170 require.True(t, b)
171 require.Equal(t, HeadSeriesRef(2), j.seriesRef)
172
173 popTime <- time.Now()
174 }()
175
176 queue.push(chunkWriteJob{seriesRef: 1})
177
178 timeBeforePop := <-popTime
179
180 delay := 100 * time.Millisecond
181 select {
182 case <-time.After(delay):
183 // ok
184 case <-popTime:
185 require.Fail(t, "didn't expect another pop to proceed")
186 }
187
188 pushTime := time.Now()
189 require.True(t, queue.push(chunkWriteJob{seriesRef: 2}))
190
191 timeAfterPop := <-popTime
192
193 require.GreaterOrEqual(t, timeAfterPop.Sub(pushTime), time.Duration(0))
194 require.Greater(t, timeAfterPop.Sub(timeBeforePop), delay)
195}
196
197func TestQueuePopUnblocksOnClose(t *testing.T) {
198 t.Parallel()

Callers

nothing calls this directly

Calls 7

newWriteJobQueueFunction · 0.85
HeadSeriesRefTypeAlias · 0.85
FailMethod · 0.80
DurationMethod · 0.80
popMethod · 0.45
pushMethod · 0.45
SubMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…