Skip to content

Commit a594098

Browse files
cjihrigpichlermarc
andauthored
test(shim-opentracing): add comparison thresholds in flaky assertions (#5974)
Co-authored-by: Marc Pichler <[email protected]>
1 parent 977c8a4 commit a594098

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
1616

1717
### :bug: Bug Fixes
1818

19+
* test(shim-opentracing): add comparison thresholds in flaky assertions [#5974](https://github.com/open-telemetry/opentelemetry-js/pull/5974) @cjihrig
20+
1921
### :books: Documentation
2022

2123
### :house: Internal

packages/opentelemetry-shim-opentracing/test/Shim.test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ import {
4242
ATTR_EXCEPTION_TYPE,
4343
} from '@opentelemetry/semantic-conventions';
4444

45+
function assertWithinThreshold(
46+
actual: number,
47+
expected: number,
48+
threshold: number
49+
) {
50+
assert.ok(
51+
Math.abs(actual - expected) <= threshold,
52+
`actual (${actual}) and expected (${expected}) not within threshold of ${threshold}`
53+
);
54+
}
55+
4556
describe('OpenTracing Shim', () => {
4657
const compositePropagator = new CompositePropagator({
4758
propagators: [new W3CTraceContextPropagator(), new W3CBaggagePropagator()],
@@ -263,9 +274,10 @@ describe('OpenTracing Shim', () => {
263274
const adjustment = (otSpan as any)['_performanceOffset'];
264275

265276
assert.strictEqual(otSpan.links.length, 1);
266-
assert.deepStrictEqual(
277+
assertWithinThreshold(
267278
hrTimeToMilliseconds(otSpan.startTime),
268-
now + adjustment + performance.timeOrigin
279+
now + adjustment + performance.timeOrigin,
280+
0.001
269281
);
270282
assert.deepStrictEqual(otSpan.attributes, opentracingOptions.tags);
271283
});
@@ -497,9 +509,10 @@ describe('OpenTracing Shim', () => {
497509
const now = performance.now();
498510
span.finish(now);
499511
const adjustment = (otSpan as any)['_performanceOffset'];
500-
assert.deepStrictEqual(
512+
assertWithinThreshold(
501513
hrTimeToMilliseconds(otSpan.endTime),
502-
now + adjustment + performance.timeOrigin
514+
now + adjustment + performance.timeOrigin,
515+
0.001
503516
);
504517
});
505518

0 commit comments

Comments
 (0)