MCPcopy
hub / github.com/grafana/dskit / TestInstrumentedGate

Function TestInstrumentedGate

gate/gate_test.go:68–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestInstrumentedGate(t *testing.T) {
69 t.Run("max concurrency", func(t *testing.T) {
70 concurrency := 1
71 reg := prometheus.NewPedanticRegistry()
72 _ = NewInstrumented(reg, concurrency, NewNoop())
73
74 require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
75 # HELP gate_queries_concurrent_max Number of maximum concurrent queries allowed.
76 # TYPE gate_queries_concurrent_max gauge
77 gate_queries_concurrent_max 1
78 `), "gate_queries_concurrent_max"))
79 })
80
81 t.Run("inflight requests", func(t *testing.T) {
82 concurrency := 1
83 reg := prometheus.NewPedanticRegistry()
84 g := NewInstrumented(reg, concurrency, NewNoop())
85
86 require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
87 # HELP gate_queries_in_flight Number of queries that are currently in flight.
88 # TYPE gate_queries_in_flight gauge
89 gate_queries_in_flight 0
90 `), "gate_queries_in_flight"))
91
92 require.NoError(t, g.Start(context.Background()))
93
94 require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
95 # HELP gate_queries_in_flight Number of queries that are currently in flight.
96 # TYPE gate_queries_in_flight gauge
97 gate_queries_in_flight 1
98 `), "gate_queries_in_flight"))
99 })
100}

Callers

nothing calls this directly

Calls 4

NewInstrumentedFunction · 0.85
NewNoopFunction · 0.85
RunMethod · 0.80
StartMethod · 0.65

Tested by

no test coverage detected