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 1
1
import { busyWaitForNanoSeconds , sleep } from "./sleep.function" ;
2
2
3
+ const maxTimeDeltaInMs = 3 ;
4
+
3
5
describe ( "sleep" , ( ) => {
4
6
it ( "should resolve after x ms" , async ( ) => {
5
7
// GIVEN
@@ -9,24 +11,25 @@ describe("sleep", () => {
9
11
const before = Date . now ( ) ;
10
12
await sleep ( timeout ) ;
11
13
const after = Date . now ( ) ;
14
+ const delta = Math . abs ( after - before ) ;
12
15
13
16
// THEN
14
- expect ( after - before ) . toBeGreaterThanOrEqual ( timeout ) ;
17
+ expect ( delta ) . toBeLessThanOrEqual ( maxTimeDeltaInMs ) ;
15
18
} ) ;
16
19
} ) ;
17
20
18
21
describe ( "busyWaitForNanoSeconds" , ( ) => {
19
22
it ( "should resolve after x ns" , async ( ) => {
20
23
// GIVEN
21
24
const timeoutNs = 5_000_000 ;
22
- const timeoutMs = 5 ;
23
25
24
26
// WHEN
25
27
const before = Date . now ( ) ;
26
28
await busyWaitForNanoSeconds ( timeoutNs ) ;
27
29
const after = Date . now ( ) ;
30
+ const delta = Math . abs ( after - before ) ;
28
31
29
32
// THEN
30
- expect ( after - before ) . toBeGreaterThanOrEqual ( timeoutMs ) ;
33
+ expect ( delta ) . toBeLessThanOrEqual ( maxTimeDeltaInMs ) ;
31
34
} ) ;
32
35
} ) ;
You can’t perform that action at this time.
0 commit comments