Skip to content

Commit 15767e3

Browse files
Pigrabbitzbjornson
authored andcommitted
test: add failing test case
Histogram.startTimer fails when exemplars enabled.
1 parent c171309 commit 15767e3

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/exemplarsTest.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,39 @@ describe('Exemplars', () => {
122122
}).toThrowError('Label set size must be smaller than 128 UTF-8 chars');
123123
});
124124

125+
it('should time request, with exemplar', async () => {
126+
jest.useFakeTimers('modern');
127+
jest.setSystemTime(0);
128+
const histogramInstance = new Histogram({
129+
name: 'histogram_start_timer_exemplar_test',
130+
help: 'test',
131+
labelNames: ['method', 'code'],
132+
enableExemplars: true,
133+
});
134+
const end = histogramInstance.startTimer({
135+
method: 'get',
136+
code: '200',
137+
});
138+
139+
jest.advanceTimersByTime(500);
140+
end();
141+
142+
const valuePair = getValueByLabel(
143+
0.5,
144+
(await histogramInstance.get()).values,
145+
);
146+
expect(valuePair.value).toEqual(1);
147+
jest.useRealTimers();
148+
});
149+
150+
function getValueByLabel(label, values, key) {
151+
return values.reduce((acc, val) => {
152+
if (val.labels && val.labels[key || 'le'] === label) {
153+
acc = val;
154+
}
155+
return acc;
156+
}, {});
157+
}
125158
function getValuesByLabel(label, values, key) {
126159
return values.reduce((acc, val) => {
127160
if (val.labels && val.labels[key || 'le'] === label) {

0 commit comments

Comments
 (0)