Skip to content

Commit

Permalink
Merge f62ab0d into 2b59c28
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Feb 6, 2023
2 parents 2b59c28 + f62ab0d commit 9f99a84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
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

0 comments on commit 9f99a84

Please sign in to comment.