File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 11import { busyWaitForNanoSeconds , sleep } from "./sleep.function" ;
22
3+ const maxTimeDeltaInMs = 3 ;
4+
35describe ( "sleep" , ( ) => {
46 it ( "should resolve after x ms" , async ( ) => {
57 // GIVEN
@@ -9,24 +11,25 @@ describe("sleep", () => {
911 const before = Date . now ( ) ;
1012 await sleep ( timeout ) ;
1113 const after = Date . now ( ) ;
14+ const delta = Math . abs ( after - before ) ;
1215
1316 // THEN
14- expect ( after - before ) . toBeGreaterThanOrEqual ( timeout ) ;
17+ expect ( delta ) . toBeLessThanOrEqual ( maxTimeDeltaInMs ) ;
1518 } ) ;
1619} ) ;
1720
1821describe ( "busyWaitForNanoSeconds" , ( ) => {
1922 it ( "should resolve after x ns" , async ( ) => {
2023 // GIVEN
2124 const timeoutNs = 5_000_000 ;
22- const timeoutMs = 5 ;
2325
2426 // WHEN
2527 const before = Date . now ( ) ;
2628 await busyWaitForNanoSeconds ( timeoutNs ) ;
2729 const after = Date . now ( ) ;
30+ const delta = Math . abs ( after - before ) ;
2831
2932 // THEN
30- expect ( after - before ) . toBeGreaterThanOrEqual ( timeoutMs ) ;
33+ expect ( delta ) . toBeLessThanOrEqual ( maxTimeDeltaInMs ) ;
3134 } ) ;
3235} ) ;
You can’t perform that action at this time.
0 commit comments