Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions test/throttle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ describe('throttle', function() {
await sleep(sleepTime);
}

assert.equal(expectedExecutions, executions);
assert.equal(executions, expectedExecutions);
});

it('function should be throttled (4 function calls in 600ms', async function() {
this.timeout(5000);
var functionCalls = 30;
var sleepTime = 20; // 30*20 = 600 ms
var throttleDelay = 200;
var expectedExecutions = 3 + 1; // Call functions for 600 ms with 200 ms throttle = 3 calls + one last call
// Call functions for 600 ms with 200 ms throttle = 3 calls + one last call
// this is LowerBound as in slower environments there could be more executions
// less than the lowerBound isn't possible due to the deterministic sleepTime, and throttleDelay values
var expectedExecutionsLowerBound = 3 + 1;
var executions = 0;

var f = throttle(throttleDelay, function() {
Expand All @@ -42,8 +45,7 @@ describe('throttle', function() {
f();
await sleep(sleepTime);
}

assert.equal(expectedExecutions, executions);
assert.equal(expectedExecutionsLowerBound <= executions, true);
});

});