Skip to content

Commit

Permalink
test(sdk-metrics): test that NaN is ignored by histogram accumulations
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc committed Feb 1, 2024
1 parent d046310 commit 4c7ca1a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/sdk-metrics/test/aggregator/ExponentialHistogram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ describe('ExponentialHistogramAccumulation', () => {
}
});
});

it('ignores NaN', () => {
const accumulation = new ExponentialHistogramAccumulation([0, 0], 1);
accumulation.record(NaN);
assert.strictEqual(accumulation.scale, 0);
assert.strictEqual(accumulation.max, -Infinity);
assert.strictEqual(accumulation.min, Infinity);
assert.strictEqual(accumulation.sum, 0);
assert.strictEqual(accumulation.count, 0);
assert.deepStrictEqual(getCounts(accumulation.positive), []);
assert.deepStrictEqual(getCounts(accumulation.negative), []);
});
});
describe('merge', () => {
it('handles simple (even) case', () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/sdk-metrics/test/aggregator/Histogram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ describe('HistogramAccumulation', () => {
accumulation.record(value);
}
});

it('ignores NaN', () => {
const accumulation = new HistogramAccumulation([0, 0], [1, 10, 100]);
accumulation.record(NaN);

const pointValue = accumulation.toPointValue();
assert.strictEqual(pointValue.max, -Infinity);
assert.strictEqual(pointValue.min, Infinity);
assert.strictEqual(pointValue.sum, 0);
assert.strictEqual(pointValue.count, 0);
assert.deepStrictEqual(pointValue.buckets.counts, [0, 0, 0, 0]);
});
});

describe('setStartTime', () => {
Expand Down

0 comments on commit 4c7ca1a

Please sign in to comment.