@@ -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+
4556describe ( '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