| 19 | } |
| 20 | |
| 21 | func 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 | |
| 51 | func TestWorkerPool_ShouldFallbackWhenAllWorkersAreBusy(t *testing.T) { |
| 52 | reg := prometheus.NewPedanticRegistry() |