File tree 1 file changed +6
-4
lines changed
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -23,15 +23,18 @@ describe('throttle', function() {
23
23
await sleep ( sleepTime ) ;
24
24
}
25
25
26
- assert . equal ( expectedExecutions , executions ) ;
26
+ assert . equal ( executions , expectedExecutions ) ;
27
27
} ) ;
28
28
29
29
it ( 'function should be throttled (4 function calls in 600ms' , async function ( ) {
30
30
this . timeout ( 5000 ) ;
31
31
var functionCalls = 30 ;
32
32
var sleepTime = 20 ; // 30*20 = 600 ms
33
33
var throttleDelay = 200 ;
34
- var expectedExecutions = 3 + 1 ; // Call functions for 600 ms with 200 ms throttle = 3 calls + one last call
34
+ // Call functions for 600 ms with 200 ms throttle = 3 calls + one last call
35
+ // this is LowerBound as in slower environments there could be more executions
36
+ // less than the lowerBound isn't possible due to the deterministic sleepTime, and throttleDelay values
37
+ var expectedExecutionsLowerBound = 3 + 1 ;
35
38
var executions = 0 ;
36
39
37
40
var f = throttle ( throttleDelay , function ( ) {
@@ -42,8 +45,7 @@ describe('throttle', function() {
42
45
f ( ) ;
43
46
await sleep ( sleepTime ) ;
44
47
}
45
-
46
- assert . equal ( expectedExecutions , executions ) ;
48
+ assert . equal ( expectedExecutionsLowerBound <= executions , true ) ;
47
49
} ) ;
48
50
49
51
} ) ;
You can’t perform that action at this time.
0 commit comments