|
31 | 31 | #include <xrpl/protocol/jss.h> |
32 | 32 |
|
33 | 33 | #include <chrono> |
| 34 | +#include <cstdint> |
34 | 35 | #include <string> |
35 | 36 |
|
36 | 37 | using namespace rpc; |
@@ -197,67 +198,60 @@ TEST_F(RPCCountersMockPrometheusTests, onInternalError) |
197 | 198 | counters.onInternalError(); |
198 | 199 | } |
199 | 200 |
|
200 | | -TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestCurrent) |
| 201 | +struct RPCCountersMockPrometheusRecotdLedgerRequestTest : RPCCountersMockPrometheusTests { |
| 202 | + testing::StrictMock<util::prometheus::MockHistogramImpl<int64_t>>& ageLedgersHistogramMock = |
| 203 | + makeMock<util::prometheus::HistogramInt>("rpc_requested_ledger_age_histogram", ""); |
| 204 | +}; |
| 205 | +TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, currentLedger) |
201 | 206 | { |
202 | | - auto& currentCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"current\"}"); |
203 | | - EXPECT_CALL(currentCounterMock, add(1)); |
204 | | - |
| 207 | + // "current" is not tracked in the histogram (it's not a historical ledger lookup) |
| 208 | + // No mock expectations needed |
205 | 209 | boost::json::object params; |
206 | 210 | params["ledger_index"] = "current"; |
207 | 211 | counters.recordLedgerRequest(params, 1000); |
208 | 212 | } |
209 | 213 |
|
210 | | -TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestValidated) |
| 214 | +TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, validateLedger) |
211 | 215 | { |
212 | | - auto& validatedCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"validated\"}"); |
213 | | - EXPECT_CALL(validatedCounterMock, add(1)); |
| 216 | + EXPECT_CALL(ageLedgersHistogramMock, observe(0)); |
214 | 217 |
|
215 | 218 | boost::json::object params; |
216 | 219 | params["ledger_index"] = "validated"; |
217 | 220 | counters.recordLedgerRequest(params, 1000); |
218 | 221 | } |
219 | 222 |
|
220 | | -TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestValidatedDefault) |
| 223 | +TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, validatedDefaultLedger) |
221 | 224 | { |
222 | | - auto& validatedCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"validated\"}"); |
223 | | - EXPECT_CALL(validatedCounterMock, add(1)); |
| 225 | + EXPECT_CALL(ageLedgersHistogramMock, observe(0)); |
224 | 226 |
|
225 | 227 | boost::json::object params; |
226 | 228 | counters.recordLedgerRequest(params, 1000); |
227 | 229 | } |
228 | 230 |
|
229 | | -TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestSpecificNumber) |
| 231 | +TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, specificLedger) |
230 | 232 | { |
231 | | - auto& specificCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"specific\"}"); |
232 | 233 | auto& ageLedgersHistogramMock = makeMock<util::prometheus::HistogramInt>("rpc_requested_ledger_age_histogram", ""); |
233 | 234 |
|
234 | | - EXPECT_CALL(specificCounterMock, add(1)); |
235 | 235 | EXPECT_CALL(ageLedgersHistogramMock, observe(100)); // age is 1000 - 900 = 100 |
236 | 236 |
|
237 | 237 | boost::json::object params; |
238 | 238 | params["ledger_index"] = 900; |
239 | 239 | counters.recordLedgerRequest(params, 1000); |
240 | 240 | } |
241 | 241 |
|
242 | | -TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestSpecificStringNumber) |
| 242 | +TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, stringNumberLedger) |
243 | 243 | { |
244 | | - auto& specificCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"specific\"}"); |
245 | | - auto& ageLedgersHistogramMock = makeMock<util::prometheus::HistogramInt>("rpc_requested_ledger_age_histogram", ""); |
246 | | - |
247 | | - EXPECT_CALL(specificCounterMock, add(1)); |
248 | 244 | EXPECT_CALL(ageLedgersHistogramMock, observe(50)); // 1000 - 950 = 50 ledgers |
249 | 245 |
|
250 | 246 | boost::json::object params; |
251 | 247 | params["ledger_index"] = "950"; |
252 | 248 | counters.recordLedgerRequest(params, 1000); |
253 | 249 | } |
254 | 250 |
|
255 | | -TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestZeroAge) |
| 251 | +TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, zeroAgeLedger) |
256 | 252 | { |
257 | | - auto& specificCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"specific\"}"); |
258 | 253 | auto& ageLedgersHistogramMock = makeMock<util::prometheus::HistogramInt>("rpc_requested_ledger_age_histogram", ""); |
259 | 254 |
|
260 | | - EXPECT_CALL(specificCounterMock, add(1)); |
261 | 255 | EXPECT_CALL(ageLedgersHistogramMock, observe(0)); // 1000 - 1000 = 0 ledgers |
262 | 256 |
|
263 | 257 | boost::json::object params; |
|
0 commit comments