MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestWorkerPool_TestMetric

Function TestWorkerPool_TestMetric

pkg/util/worker_pool_test.go:21–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19}
20
21func TestWorkerPool_TestMetric(t *testing.T) {
22 reg := prometheus.NewPedanticRegistry()
23 workerPool := NewWorkerPool("test1", 1, reg)
24 defer workerPool.Stop()
25
26 require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
27 # HELP cortex_worker_pool_fallback_total The total number additional go routines that needed to be created to run jobs.
28 # TYPE cortex_worker_pool_fallback_total counter
29 cortex_worker_pool_fallback_total{name="test1"} 0
30`), "cortex_worker_pool_fallback_total"))
31
32 wg := &sync.WaitGroup{}
33 wg.Add(1)
34
35 // Block the first job
36 workerPool.Submit(func() {
37 wg.Wait()
38 })
39
40 // create an extra job to increment the metric
41 workerPool.Submit(func() {})
42 require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
43 # HELP cortex_worker_pool_fallback_total The total number additional go routines that needed to be created to run jobs.
44 # TYPE cortex_worker_pool_fallback_total counter
45 cortex_worker_pool_fallback_total{name="test1"} 1
46`), "cortex_worker_pool_fallback_total"))
47
48 wg.Done()
49}
50
51func TestWorkerPool_ShouldFallbackWhenAllWorkersAreBusy(t *testing.T) {
52 reg := prometheus.NewPedanticRegistry()

Callers

nothing calls this directly

Calls 6

NewWorkerPoolFunction · 0.85
DoneMethod · 0.80
StopMethod · 0.65
SubmitMethod · 0.65
AddMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected