Make rate limiter tests more tolerant of slight timing variations.

This package contains some of the most fragile tests in the entire
codebase, in large part because the author did not account for the
nondeterminism of JS timers across platforms and test runs.
This commit is contained in:
Ben Newman
2017-10-11 16:34:13 -04:00
committed by Ben Newman
parent f9df851134
commit 5da7ebdfe7

View File

@@ -95,7 +95,7 @@ testAsyncMulti("ddp rate limiter - callbacks get passed correct arguments", [
Meteor.call(
"getLastRateLimitEvent", expect(function (error, result) {
test.isTrue(result.reply.allowed);
test.isTrue(result.reply.timeToReset < RATE_LIMIT_INTERVAL_TIME_MS);
test.isTrue(result.reply.timeToReset < RATE_LIMIT_INTERVAL_TIME_MS + 100);
test.equal(result.reply.numInvocationsLeft, 4);
test.equal(result.ruleInput.userId, Meteor.userId());
@@ -118,7 +118,7 @@ testAsyncMulti("ddp rate limiter - callbacks get passed correct arguments", [
Meteor.call(
"getLastRateLimitEvent", expect(function (error, result) {
test.isFalse(result.reply.allowed);
test.isTrue(result.reply.timeToReset < RATE_LIMIT_INTERVAL_TIME_MS);
test.isTrue(result.reply.timeToReset < RATE_LIMIT_INTERVAL_TIME_MS + 100);
test.equal(result.reply.numInvocationsLeft, 0);
test.equal(result.ruleInput.userId, Meteor.userId());