Skip to content

Commit

Permalink
test: add failing test case
Browse files Browse the repository at this point in the history
Histogram.startTimer fails when exemplars enabled.
  • Loading branch information
Pigrabbit authored and zbjornson committed Nov 25, 2023
1 parent c171309 commit 15767e3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/exemplarsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,39 @@ describe('Exemplars', () => {
}).toThrowError('Label set size must be smaller than 128 UTF-8 chars');
});

it('should time request, with exemplar', async () => {
jest.useFakeTimers('modern');
jest.setSystemTime(0);
const histogramInstance = new Histogram({
name: 'histogram_start_timer_exemplar_test',
help: 'test',
labelNames: ['method', 'code'],
enableExemplars: true,
});
const end = histogramInstance.startTimer({
method: 'get',
code: '200',
});

jest.advanceTimersByTime(500);
end();

const valuePair = getValueByLabel(
0.5,
(await histogramInstance.get()).values,
);
expect(valuePair.value).toEqual(1);
jest.useRealTimers();
});

function getValueByLabel(label, values, key) {
return values.reduce((acc, val) => {
if (val.labels && val.labels[key || 'le'] === label) {
acc = val;
}
return acc;
}, {});
}
function getValuesByLabel(label, values, key) {
return values.reduce((acc, val) => {
if (val.labels && val.labels[key || 'le'] === label) {
Expand Down

0 comments on commit 15767e3

Please sign in to comment.