Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk-metrics): fix flaky LastValueAggregator test by using fake timer #3587

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :house: (Internal)

* fix(sdk-metrics): ix flaky LastValueAggregator test by using fake timer [#3587](https://github.com/open-telemetry/opentelemetry-js/pull/3587) @pichlermarc

## 1.9.1

### :bug: (Bug Fix)
Expand Down
23 changes: 17 additions & 6 deletions packages/sdk-metrics/test/aggregator/LastValue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,26 @@

import { HrTime } from '@opentelemetry/api';
import * as assert from 'assert';
import * as sinon from 'sinon';
import { AggregationTemporality } from '../../src';
import {
LastValueAccumulation,
LastValueAggregator,
} from '../../src/aggregator';
import { MetricData, DataPointType } from '../../src/export/MetricData';
import { commonValues, defaultInstrumentDescriptor, sleep } from '../util';
import { commonValues, defaultInstrumentDescriptor } from '../util';

describe('LastValueAggregator', () => {
let clock: sinon.SinonFakeTimers;

beforeEach(() => {
clock = sinon.useFakeTimers();
});

afterEach(() => {
sinon.restore();
});

describe('createAccumulation', () => {
it('no exceptions on createAccumulation', () => {
const aggregator = new LastValueAggregator();
Expand All @@ -47,16 +58,16 @@ describe('LastValueAggregator', () => {
assert.deepStrictEqual(aggregator.merge(prev, delta), expected);
});

it('return the newly sampled accumulation', async () => {
it('return the newly sampled accumulation', () => {
const aggregator = new LastValueAggregator();
const accumulation1 = aggregator.createAccumulation([0, 0]);
const accumulation2 = aggregator.createAccumulation([1, 1]);

accumulation1.record(2);
await sleep(1);
clock.tick(100);
accumulation2.record(3);
// refresh the accumulation1
await sleep(1);
clock.tick(100);
accumulation1.record(4);

assert.deepStrictEqual(
Expand Down Expand Up @@ -92,15 +103,15 @@ describe('LastValueAggregator', () => {
assert.deepStrictEqual(aggregator.diff(prev, curr), expected);
});

it('return the newly sampled accumulation', async () => {
it('return the newly sampled accumulation', () => {
const aggregator = new LastValueAggregator();
const accumulation1 = aggregator.createAccumulation([0, 0]);
const accumulation2 = aggregator.createAccumulation([1, 1]);

accumulation1.record(2);
accumulation2.record(3);
// refresh the accumulation1
await sleep(1);
clock.tick(100);
accumulation1.record(4);

assert.deepStrictEqual(
Expand Down